Fix an error path memleak
[metze/samba/wip.git] / source3 / libsmb / clifile.c
index 733abb6510ce6f2523005440b5c236ba3b51fc83..ecb2bf0f5a31101b71878127794dc0bff769240a 100644 (file)
@@ -783,10 +783,15 @@ int cli_nt_create(struct cli_state *cli, const char *fname, uint32 DesiredAccess
 
 uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str)
 {
-       size_t buflen = talloc_get_size(buf);
+       size_t buflen;
        char *converted;
        size_t converted_size;
 
+       if (buf == NULL) {
+               return NULL;
+       }
+
+       buflen = talloc_get_size(buf);
        /*
         * We're pushing into an SMB buffer, align odd
         */
@@ -809,6 +814,7 @@ uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str)
        buf = TALLOC_REALLOC_ARRAY(NULL, buf, uint8_t,
                                   buflen + converted_size);
        if (buf == NULL) {
+               TALLOC_FREE(converted);
                return NULL;
        }
 
@@ -895,7 +901,7 @@ struct async_req *cli_open_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
        }
 
        result = cli_request_send(mem_ctx, ev, cli, SMBopenX, additional_flags,
-                                 15, vwv, talloc_get_size(bytes), bytes);
+                                 15, vwv, 0, talloc_get_size(bytes), bytes);
        TALLOC_FREE(bytes);
        return result;
 }
@@ -974,7 +980,7 @@ struct async_req *cli_close_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
        SSVAL(vwv+0, 0, fnum);
        SIVALS(vwv+1, 0, -1);
 
-       return cli_request_send(mem_ctx, ev, cli, SMBclose, 0, 3, vwv,
+       return cli_request_send(mem_ctx, ev, cli, SMBclose, 0, 3, vwv, 0,
                                0, NULL);
 }