s4:client/client.c - fix "asprintf"s
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Thu, 27 May 2010 14:59:14 +0000 (16:59 +0200)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Fri, 28 May 2010 08:04:45 +0000 (10:04 +0200)
Fix the result values or change them into "talloc_asprintf"s where possible

see bug #6404

source4/client/client.c

index cf834b9e1fa6b5c74fe7cc819343d574df649a24..2a2c8ac5a34a91c9a703b09cd1f354347e5365d0 100644 (file)
@@ -863,18 +863,19 @@ static void do_mget(struct smbclient_context *ctx, struct clilist_file_info *fin
                return;
 
        if (finfo->attrib & FILE_ATTRIBUTE_DIRECTORY)
-               asprintf(&quest, "Get directory %s? ",finfo->name);
+               quest = talloc_asprintf(ctx, "Get directory %s? ",finfo->name);
        else
-               asprintf(&quest, "Get file %s? ",finfo->name);
+               quest = talloc_asprintf(ctx, "Get file %s? ",finfo->name);
 
        if (ctx->prompt && !yesno(quest)) return;
 
-       SAFE_FREE(quest);
+       talloc_free(quest);
 
        if (!(finfo->attrib & FILE_ATTRIBUTE_DIRECTORY)) {
-               asprintf(&rname, "%s%s",ctx->remote_cur_dir,finfo->name);
+               rname = talloc_asprintf(&ctx, "%s%s",ctx->remote_cur_dir,
+                                       finfo->name);
                do_get(ctx, rname, finfo->name, false);
-               SAFE_FREE(rname);
+               talloc_free(rname);
                return;
        }
 
@@ -2832,7 +2833,7 @@ static void completion_remote_filter(struct clilist_file_info *f, const char *ma
 static char **remote_completion(const char *text, int len)
 {
        char *dirmask;
-       int i;
+       int i, ret;
        completion_remote_t info;
 
        info.samelen = len;
@@ -2855,9 +2856,14 @@ static char **remote_completion(const char *text, int len)
        if (i > 0) {
                info.dirmask = talloc_strndup(NULL, text, i+1);
                info.dirmask[i+1] = 0;
-               asprintf(&dirmask, "%s%*s*", rl_ctx->remote_cur_dir, i-1, text);
-       } else
-               asprintf(&dirmask, "%s*", rl_ctx->remote_cur_dir);
+               ret = asprintf(&dirmask, "%s%*s*", rl_ctx->remote_cur_dir, i-1,
+                              text);
+       } else {
+               ret = asprintf(&dirmask, "%s*", rl_ctx->remote_cur_dir);
+       }
+       if (ret < 0) {
+               goto cleanup;
+       }
 
        if (smbcli_list(rl_ctx->cli->tree, dirmask, 
                     FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,