hush: plug a memory leak
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 12 Jan 2010 05:47:39 +0000 (06:47 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 12 Jan 2010 05:47:39 +0000 (06:47 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/hush.c
shell/hush_test/hush-z_slow/leak_empty_tick.right [new file with mode: 0644]
shell/hush_test/hush-z_slow/leak_empty_tick.tests [new file with mode: 0755]

index 25094654dab21800f51ed87d0acefb87b483e750..d02e68d496a5ef08b64d215b10feaea3b8703335 100644 (file)
@@ -4136,6 +4136,7 @@ static NOINLINE int run_pipe(struct pipe *pi)
 
                /* if someone gives us an empty string: `cmd with empty output` */
                if (!argv_expanded[0]) {
+                       free(argv_expanded);
                        debug_leave();
                        return G.last_exitcode;
                }
diff --git a/shell/hush_test/hush-z_slow/leak_empty_tick.right b/shell/hush_test/hush-z_slow/leak_empty_tick.right
new file mode 100644 (file)
index 0000000..c6f0334
--- /dev/null
@@ -0,0 +1,3 @@
+Warm up
+Measuring memory leak...
+Ok
diff --git a/shell/hush_test/hush-z_slow/leak_empty_tick.tests b/shell/hush_test/hush-z_slow/leak_empty_tick.tests
new file mode 100755 (executable)
index 0000000..ae37579
--- /dev/null
@@ -0,0 +1,28 @@
+echo "Warm up"
+i=1
+while test $i != 9; do
+    `true`
+    : $((i++))
+done
+
+memleak
+
+echo "Measuring memory leak..."
+i=1
+while test $i != 199; do
+    `true`
+    : $((i++))
+done
+i=1
+while test $i != 199; do
+    `true`
+    : $((i++))
+done
+
+memleak
+kb=$?
+if test $kb -le 4; then
+    echo Ok #$kb
+else
+    echo "Bad: $kb kb (or more) leaked"
+fi