messaging4: Move str_list_add
authorVolker Lendecke <vl@samba.org>
Thu, 17 Jul 2014 14:09:14 +0000 (14:09 +0000)
committerVolker Lendecke <vl@samba.org>
Mon, 21 Jul 2014 16:00:10 +0000 (18:00 +0200)
If this fails, we'd have to revert the tdb_append. str_list_remove is
simpler :-)

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source4/lib/messaging/messaging.c

index 5def9d1f7343f0d6494ee23fe3288de1a6c614e6..dde796f8d17952cbf63c76982a4e208853471c3f 100644 (file)
@@ -930,21 +930,22 @@ NTSTATUS irpc_add_name(struct imessaging_context *msg_ctx, const char *name)
        int ret;
        NTSTATUS status = NT_STATUS_OK;
 
+       msg_ctx->names = str_list_add(msg_ctx->names, name);
+       if (msg_ctx->names == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       talloc_steal(msg_ctx, msg_ctx->names);
+
        key = string_term_tdb_data(name);
        data = (TDB_DATA) { .dptr = (uint8_t *)&pid, .dsize = sizeof(pid) };
 
        ret = tdb_append(t, key, data);
        if (ret != 0) {
                enum TDB_ERROR err = tdb_error(t);
+               str_list_remove(msg_ctx->names, name);
                return map_nt_error_from_tdb(err);
        }
 
-       msg_ctx->names = str_list_add(msg_ctx->names, name);
-       if (msg_ctx->names == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       talloc_steal(msg_ctx, msg_ctx->names);
-
        return status;
 }