s3-rpc_client: Close the hive handle before we open it again.
authorAndreas Schneider <asn@samba.org>
Mon, 25 Jul 2011 15:48:08 +0000 (17:48 +0200)
committerAndreas Schneider <asn@samba.org>
Wed, 27 Jul 2011 06:49:58 +0000 (08:49 +0200)
source3/rpc_client/cli_winreg_spoolss.c

index d0c048c3cc85f4bbaf201fa2b45e61a7b04e5e65..ebdd419a6557971850eece980379b116491edb86 100644 (file)
@@ -599,6 +599,7 @@ WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
        uint32_t i, count = ARRAY_SIZE(subkeys);
        uint32_t info2_mask = 0;
        WERROR result = WERR_OK;
+       WERROR ignore;
        TALLOC_CTX *tmp_ctx;
 
        tmp_ctx = talloc_stackframe();
@@ -634,6 +635,13 @@ WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
+       if (is_valid_policy_hnd(&key_hnd)) {
+               dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
+       }
+       if (is_valid_policy_hnd(&hive_hnd)) {
+               dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
+       }
+
        /* Create the main key */
        result = winreg_printer_openkey(tmp_ctx,
                                        winreg_handle,
@@ -902,15 +910,11 @@ WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
                                       secdesc);
 
 done:
-       if (winreg_handle != NULL) {
-               WERROR ignore;
-
-               if (is_valid_policy_hnd(&key_hnd)) {
-                       dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
-               }
-               if (is_valid_policy_hnd(&hive_hnd)) {
-                       dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
-               }
+       if (is_valid_policy_hnd(&key_hnd)) {
+               dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
+       }
+       if (is_valid_policy_hnd(&hive_hnd)) {
+               dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
        }
 
        talloc_free(tmp_ctx);