ctdb: Fix memleak in ctdb_get_script_list
authorVolker Lendecke <vl@samba.org>
Fri, 13 Mar 2015 14:12:41 +0000 (14:12 +0000)
committerMichael Adam <obnox@samba.org>
Fri, 13 Mar 2015 15:39:05 +0000 (16:39 +0100)
scandir allocates every name individually, see example code in susv4 or man
scandir

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
ctdb/server/eventscript.c

index 4cbb846ed9c946e0798936a46158acbfed8e1393..a47396a8ad98186349401c40c1426a6f4ed8cce2 100644 (file)
@@ -177,8 +177,7 @@ static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb,
                                   + sizeof(scripts->scripts[0]) * count);
        if (scripts == NULL) {
                DEBUG(DEBUG_ERR, (__location__ " Failed to allocate scripts\n"));
-               free(namelist);
-               return NULL;
+               goto done;
        }
        scripts->num_scripts = count;
 
@@ -191,6 +190,10 @@ static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb,
                }
        }
 
+done:
+       for (i=0; i<count; i++) {
+               free(namelist[i]);
+       }
        free(namelist);
        return scripts;
 }