summaryrefslogtreecommitdiffstats
path: root/src/appliance.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-11-23 12:12:33 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-11-23 12:12:33 +0000
commita6a0b9ba164f68dd79782f054604102017bc9c15 (patch)
treefd19a529e2bbd66c81ee578bde14a323d0b874f3 /src/appliance.c
parentfae8d7cafb66e0da697cde71f7e9444165c76ff7 (diff)
downloadlibguestfs-a6a0b9ba164f68dd79782f054604102017bc9c15.tar.gz
libguestfs-a6a0b9ba164f68dd79782f054604102017bc9c15.tar.xz
libguestfs-a6a0b9ba164f68dd79782f054604102017bc9c15.zip
lib: Fix memory leak and simplify command code.
Fix the following memory leak found by valgrind: ==13629== 498 (112 direct, 386 indirect) bytes in 1 blocks are definitely lost in loss record 99 of 110 ==13629== at 0x4A06B2F: calloc (vg_replace_malloc.c:593) ==13629== by 0x4CA564E: guestfs_safe_calloc (alloc.c:71) ==13629== by 0x4CA9B02: guestfs___new_command (command.c:143) ==13629== by 0x4CA66E9: guestfs___build_appliance (appliance.c:690) ==13629== by 0x4CBD1B9: launch_libvirt (launch-libvirt.c:188) ==13629== by 0x402E7E: main (virt-filesystems.c:349) Also adjust the command code in several places to make it simpler. We can almost always call guestfs___cmd_close right after guestfs___cmd_run, avoiding any need to close the handle along error paths. Tested by running the test suite under valgrind.
Diffstat (limited to 'src/appliance.c')
-rw-r--r--src/appliance.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/appliance.c b/src/appliance.c
index 8a22064b..e7ba60df 100644
--- a/src/appliance.c
+++ b/src/appliance.c
@@ -286,12 +286,10 @@ calculate_supermin_checksum (guestfs_h *g, const char *supermin_path)
guestfs___cmd_set_stdout_callback (cmd, read_checksum, checksum, 0);
r = guestfs___cmd_run (cmd);
+ guestfs___cmd_close (cmd);
/* Errors here are non-fatal, so we don't need to call error(). */
- if (r == -1) {
- guestfs___cmd_close (cmd);
+ if (r == -1)
return NULL;
- }
- guestfs___cmd_close (cmd);
debug (g, "checksum of existing appliance: %s", checksum);
@@ -707,6 +705,7 @@ run_supermin_helper (guestfs_h *g, const char *supermin_path,
guestfs___cmd_add_arg_format (cmd, "%s/root", cachedir);
r = guestfs___cmd_run (cmd);
+ guestfs___cmd_close (cmd);
if (r == -1)
return -1;
if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) {