libcli/named_pipe_auth: fix memory handling for temporary data
authorStefan Metzmacher <metze@samba.org>
Mon, 21 Jun 2010 14:13:14 +0000 (16:13 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 21 Jun 2010 14:16:15 +0000 (16:16 +0200)
In a tevent_req based function tevent_req_create() should be the first
function! If it fails it's the only reason, why the function
could every return NULL.

And all temporary data belongs to 'state' and gets free'ed by
tevent_req_received() in the _recv function.

metze

libcli/named_pipe_auth/npa_tstream.c

index 351858408c05f1681bc20e940e145c79c0c9e9ca..59d3a97dc0b127dbdfea98821ac51d064ed0fe6f 100644 (file)
@@ -73,11 +73,7 @@ struct tevent_req *tstream_npa_connect_send(TALLOC_CTX *mem_ctx,
        struct tevent_req *subreq;
        int ret;
        enum ndr_err_code ndr_err;
-       char *lower_case_npipe = strlower_talloc(mem_ctx, npipe);
-
-       if (!lower_case_npipe) {
-               return NULL;
-       }
+       char *lower_case_npipe;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct tstream_npa_connect_state);
@@ -87,6 +83,11 @@ struct tevent_req *tstream_npa_connect_send(TALLOC_CTX *mem_ctx,
 
        state->caller.ev = ev;
 
+       lower_case_npipe = strlower_talloc(state, npipe);
+       if (tevent_req_nomem(lower_case_npipe, req)) {
+               goto post;
+       }
+
        state->unix_path = talloc_asprintf(state, "%s/%s",
                                           directory,
                                           lower_case_npipe);