From 873ed765f4806042039e440c01126ae29c216ca7 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Thu, 7 Mar 2024 17:21:34 -0500 Subject: [PATCH] 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. --- libguestfs-inspect.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libguestfs-inspect.c b/libguestfs-inspect.c index 3e0d6d0..b22c7a0 100644 --- a/libguestfs-inspect.c +++ b/libguestfs-inspect.c @@ -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; }