]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
librpc: Simplify dcerpc_binding_dup() with common nomem handling
authorVolker Lendecke <vl@samba.org>
Mon, 15 Mar 2021 16:45:32 +0000 (17:45 +0100)
committerVolker Lendecke <vl@samba.org>
Fri, 19 Mar 2021 07:09:37 +0000 (07:09 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
librpc/rpc/binding.c

index 817498d8700c0fe62105d924cac88d6f0fd09655..6588f43cc9d2587a00f546729de1c5785d2ab0bf 100644 (file)
@@ -1369,39 +1369,34 @@ _PUBLIC_ struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx,
        if (b->object_string != NULL) {
                n->object_string = talloc_strdup(n, b->object_string);
                if (n->object_string == NULL) {
-                       talloc_free(n);
-                       return NULL;
+                       goto nomem;
                }
        }
        if (b->host != NULL) {
                n->host = talloc_strdup(n, b->host);
                if (n->host == NULL) {
-                       talloc_free(n);
-                       return NULL;
+                       goto nomem;
                }
        }
 
        if (b->target_hostname != NULL) {
                n->target_hostname = talloc_strdup(n, b->target_hostname);
                if (n->target_hostname == NULL) {
-                       talloc_free(n);
-                       return NULL;
+                       goto nomem;
                }
        }
 
        if (b->target_principal != NULL) {
                n->target_principal = talloc_strdup(n, b->target_principal);
                if (n->target_principal == NULL) {
-                       talloc_free(n);
-                       return NULL;
+                       goto nomem;
                }
        }
 
        if (b->endpoint != NULL) {
                n->endpoint = talloc_strdup(n, b->endpoint);
                if (n->endpoint == NULL) {
-                       talloc_free(n);
-                       return NULL;
+                       goto nomem;
                }
        }
 
@@ -1412,21 +1407,22 @@ _PUBLIC_ struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx,
 
                n->options = talloc_array(n, const char *, count + 1);
                if (n->options == NULL) {
-                       talloc_free(n);
-                       return NULL;
+                       goto nomem;
                }
 
                for (i = 0; i < count; i++) {
                        n->options[i] = talloc_strdup(n->options, b->options[i]);
                        if (n->options[i] == NULL) {
-                               talloc_free(n);
-                               return NULL;
+                               goto nomem;
                        }
                }
                n->options[count] = NULL;
        }
 
        return n;
+nomem:
+       TALLOC_FREE(n);
+       return NULL;
 }
 
 _PUBLIC_ NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,