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:
2024-03-07 17:21:34 -05:00
parent 2493f8916a
commit 873ed765f4

View File

@@ -53,7 +53,9 @@ zmsg_t *guestfs_inspect_command_to_zmsg(struct guestfs_inpsect_command *command)
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));
res->name = zmsg_popstr(msg);
@@ -85,6 +87,8 @@ struct guestfs_inpsect_command *guestfs_inspect_zmsg_to_command(zmsg_t *msg) {
}
break;
}
zmsg_destroy(&msg);
return res;
}