staging: greybus: loopback_test: fix device-name leak
authorGargi Sharma <gs051095@gmail.com>
Wed, 22 Feb 2017 15:38:21 +0000 (21:08 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 6 Mar 2017 08:17:01 +0000 (09:17 +0100)
All the device names were being always leaked. Also,
illegal free was being called upon namelist[n] which
was coincidentally NULL. The pointer to dirent structures
must be individually freed before freeing the pointer array.

Coccinelle Script:
@@
expression arr,ex1,ex2;
@@

for(ex1 = 0; ex1 < ex2; ex1++) { <...
  arr[
- ex2
+ ex1
  ]
  ...> }

Signed-off-by: Gargi Sharma <gs051095@gmail.com>
Reviewed by: Johan Hovold <johan@kernel.org>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/greybus/tools/loopback_test.c

index 18d7a3d1f3c7723b4051133907ce31aeb609425b..1c01833d1f4ea76f58bf926d4adab74a915b8a2c 100644 (file)
@@ -636,7 +636,7 @@ int find_loopback_devices(struct loopback_test *t)
        ret = 0;
 done:
        for (i = 0; i < n; i++)
-               free(namelist[n]);
+               free(namelist[i]);
        free(namelist);
 baddir:
        return ret;