Do not modify the argument we are given.
By duplicating it, we make it so popping frames off the message does not modify the argument. This make sure the value remains useful to the caller.
This commit is contained in:
@@ -53,7 +53,9 @@ zmsg_t *guestfs_inspect_command_to_zmsg(struct guestfs_inpsect_command *command)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct guestfs_inpsect_command *guestfs_inspect_zmsg_to_command(zmsg_t *msg) {
|
struct guestfs_inpsect_command *guestfs_inspect_zmsg_to_command(zmsg_t *external_msg) {
|
||||||
|
// This way we do not modify the argument we are given.
|
||||||
|
zmsg_t *msg = zmsg_dup(external_msg);
|
||||||
struct guestfs_inpsect_command *res = malloc(sizeof(struct guestfs_inpsect_command));
|
struct guestfs_inpsect_command *res = malloc(sizeof(struct guestfs_inpsect_command));
|
||||||
|
|
||||||
res->name = zmsg_popstr(msg);
|
res->name = zmsg_popstr(msg);
|
||||||
@@ -85,6 +87,8 @@ struct guestfs_inpsect_command *guestfs_inspect_zmsg_to_command(zmsg_t *msg) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
zmsg_destroy(&msg);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user