examples: Fix memory leaks in the waiter_test.
authorAndreas Schneider <asn@cryptomilk.org>
Tue, 11 Jun 2013 07:50:43 +0000 (09:50 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 11 Jun 2013 07:53:59 +0000 (09:53 +0200)
example/chef_wrap/waiter_test_wrap.c

index 1fa930b231083dec26a156f7cdd67073be3db6c3..1b8ed94385a2c5908d2d7894318255aa4d112228 100644 (file)
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <stdbool.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include <stdarg.h>
@@ -96,6 +97,7 @@ static int waiter_process(const char *order, char **dish)
 
     /* Check if we received the dish we wanted from the kitchen */
     if (strcmp(order, *dish) != 0) {
+        free(*dish);
         *dish = NULL;
         return -2;
     }
@@ -128,6 +130,9 @@ static void test_order_hotdog(void **state)
     assert_int_equal(rv, 0);
     /* And actually receive one */
     assert_string_equal(dish, "hotdog");
+    if (dish != NULL) {
+        free(dish);
+    }
 }
 
 static void test_bad_dish(void **state)