Fix memory leaks in various error flows
authorDotan Barak <dotanb@lists.openfabrics.org>
Mon, 14 Nov 2011 16:54:38 +0000 (08:54 -0800)
committerRoland Dreier <roland@purestorage.com>
Mon, 19 Dec 2011 18:03:23 +0000 (10:03 -0800)
Signed-off-by: Dotan Barak <dotanb@dev.mellanox.co.il>
Signed-off-by: Roland Dreier <roland@purestorage.com>
src/cmd.c
src/compat-1_0.c
src/init.c

index 39af833..1a04228 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -68,8 +68,10 @@ static int ibv_cmd_get_context_v2(struct ibv_context *context,
        IBV_INIT_CMD_RESP(cmd, cmd_size, GET_CONTEXT, resp, resp_size);
        cmd->cq_fd_tab = (uintptr_t) &cq_fd;
 
-       if (write(context->cmd_fd, cmd, cmd_size) != cmd_size)
+       if (write(context->cmd_fd, cmd, cmd_size) != cmd_size) {
+               free(t);
                return errno;
+       }
 
        VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
 
index 3f5ff35..fff6412 100644 (file)
@@ -238,7 +238,7 @@ struct ibv_device_1_0 **__ibv_get_device_list_1_0(int *num)
 
        l = calloc(n + 2, sizeof (struct ibv_device_1_0 *));
        if (!l)
-               return NULL;
+               goto free_device_list;
 
        l[0] = (void *) real_list;
 
@@ -258,6 +258,9 @@ fail:
        for (i = 1; i <= n; ++i)
                if (l[i])
                        free(l[i]);
+       free(l);
+
+free_device_list:
        ibv_free_device_list(real_list);
        return NULL;
 }
index 06e550d..8d6786e 100644 (file)
@@ -309,7 +309,7 @@ static void read_config(void)
                if (asprintf(&path, "%s/%s", IBV_CONFIG_DIR, dent->d_name) < 0) {
                        fprintf(stderr, PFX "Warning: couldn't read config file %s/%s.\n",
                                IBV_CONFIG_DIR, dent->d_name);
-                       return;
+                       goto out;
                }
 
                if (stat(path, &buf)) {
@@ -326,6 +326,7 @@ next:
                free(path);
        }
 
+out:
        closedir(conf_dir);
 }