Fix memory leak - free allocated by scandir() namelist elements.

Signed-off-by: Sasha Khapyorsky <[EMAIL PROTECTED]>
---
 libibumad/src/umad.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/libibumad/src/umad.c b/libibumad/src/umad.c
index 5b7b83e..1dc328d 100644
--- a/libibumad/src/umad.c
+++ b/libibumad/src/umad.c
@@ -177,6 +177,7 @@ get_port(char *ca_name, char *dir, int portnum, umad_port_t 
*port)
                idx = strtoul(namelist[i]->d_name, NULL, 0);
                sys_read_uint(port_dir, namelist[i]->d_name, &val);
                port->pkeys[idx] = val;
+               free(namelist[i]);
        }
        port->pkeys_size = ret;
        free(namelist);
@@ -188,8 +189,11 @@ get_port(char *ca_name, char *dir, int portnum, 
umad_port_t *port)
        return 0;
 
 clean:
-       if (namelist)
+       if (namelist) {
+               for (i = 0; i < ret ; i++)
+                       free(namelist[i]);
                free(namelist);
+       }
        if (port->pkeys)
                free(port->pkeys);
        return -EIO;
-- 
1.5.3.4.206.g58ba4

_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to