r14098: Fix Coverity # 112
authorVolker Lendecke <vlendec@samba.org>
Thu, 9 Mar 2006 20:42:01 +0000 (20:42 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:11:11 +0000 (11:11 -0500)
source/utils/net.c

index 99a289bcd4391168235f6c1226ab5b2d9cc9b1c5..1389885ba1776b2d0ff9a4fe7903ddaf87896e31 100644 (file)
@@ -249,12 +249,21 @@ NTSTATUS connect_dst_pipe(struct cli_state **cli_dst, struct rpc_pipe_client **p
        struct cli_state *cli_tmp = NULL;
        struct rpc_pipe_client *pipe_hnd = NULL;
 
-       if (opt_destination)
-               server_name = SMB_STRDUP(opt_destination);
+       if (server_name == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       if (opt_destination) {
+               SAFE_FREE(server_name);
+               if ((server_name = SMB_STRDUP(opt_destination)) == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+       }
 
        /* make a connection to a named pipe */
        nt_status = connect_to_ipc(&cli_tmp, NULL, server_name);
        if (!NT_STATUS_IS_OK(nt_status)) {
+               SAFE_FREE(server_name);
                return nt_status;
        }
 
@@ -262,11 +271,13 @@ NTSTATUS connect_dst_pipe(struct cli_state **cli_dst, struct rpc_pipe_client **p
        if (!pipe_hnd) {
                DEBUG(0, ("couldn't not initialize pipe\n"));
                cli_shutdown(cli_tmp);
+               SAFE_FREE(server_name);
                return nt_status;
        }
 
        *cli_dst = cli_tmp;
        *pp_pipe_hnd = pipe_hnd;
+       SAFE_FREE(server_name);
 
        return nt_status;
 }