libcli: Do not overwrite pointer on realloc failure
authorVolker Lendecke <vl@samba.org>
Wed, 18 Jan 2017 15:43:35 +0000 (16:43 +0100)
committerJeremy Allison <jra@samba.org>
Mon, 23 Jan 2017 21:46:13 +0000 (22:46 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
libcli/security/util_sid.c

index 2f3fceba228b3a19ae9cd084e7e55bcbf1953f65..2ab47f2db2c1477366a791ec8d73686eac3d2bb7 100644 (file)
@@ -337,12 +337,14 @@ int sid_compare_domain(const struct dom_sid *sid1, const struct dom_sid *sid2)
 NTSTATUS add_sid_to_array(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
                          struct dom_sid **sids, uint32_t *num)
 {
-       *sids = talloc_realloc(mem_ctx, *sids, struct dom_sid,
-                              (*num)+1);
-       if (*sids == NULL) {
+       struct dom_sid *tmp;
+
+       tmp = talloc_realloc(mem_ctx, *sids, struct dom_sid, (*num)+1);
+       if (tmp == NULL) {
                *num = 0;
                return NT_STATUS_NO_MEMORY;
        }
+       *sids = tmp;
 
        sid_copy(&((*sids)[*num]), sid);
        *num += 1;