uwrap: Fix a memory leak when we reuse an allocated id.
authorAndreas Schneider <asn@samba.org>
Fri, 20 Dec 2013 12:02:37 +0000 (13:02 +0100)
committerAndreas Schneider <asn@samba.org>
Fri, 20 Dec 2013 12:02:37 +0000 (13:02 +0100)
src/uid_wrapper.c

index 35979486b8baa8c6058c1193e70b151726c5998e..e20b3d29b7e31dc5a22427d1534b4163a405d567 100644 (file)
@@ -427,6 +427,15 @@ static int uwrap_new_id(pthread_t tid, bool do_alloc)
                        errno = ENOMEM;
                        return -1;
                }
+
+               id->groups = malloc(sizeof(gid_t) * 1);
+               if (id->groups == NULL) {
+                       errno = ENOMEM;
+                       return -1;
+               }
+
+               UWRAP_DLIST_ADD(uwrap.ids, id);
+               uwrap_tls_id = id;
        }
 
        id->tid = tid;
@@ -436,14 +445,8 @@ static int uwrap_new_id(pthread_t tid, bool do_alloc)
        id->rgid = id->egid = id->sgid = uwrap.mygid;
 
        id->ngroups = 1;
-       id->groups = malloc(sizeof(gid_t) * id->ngroups);
        id->groups[0] = uwrap.mygid;
 
-       if (do_alloc) {
-               UWRAP_DLIST_ADD(uwrap.ids, id);
-               uwrap_tls_id = id;
-       }
-
        return 0;
 }