Fixed memory leaks in file_mask_dialog() function.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2009-07-24 10:35:06 +04:00
parent 70dcbb2020
commit d0b4830e0f
1 changed files with 20 additions and 17 deletions

View File

@ -912,8 +912,8 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
const char *def_text, int only_one, int *do_background) const char *def_text, int only_one, int *do_background)
{ {
int source_easy_patterns = easy_patterns; int source_easy_patterns = easy_patterns;
char *source_mask, *orig_mask, *dest_dir, *tmpdest; char *source_mask, *orig_mask, *dest_dir, *tmp;
char *def_text_secure, *def_text_secure2; char *def_text_secure;
struct stat buf; struct stat buf;
int val; int val;
QuickDialog Quick_input; QuickDialog Quick_input;
@ -922,7 +922,6 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
fmd_init_i18n (FALSE); fmd_init_i18n (FALSE);
/* unselect checkbox if target filesystem don't support attributes */ /* unselect checkbox if target filesystem don't support attributes */
ctx->op_preserve = filegui__check_attrs_on_fs(def_text); ctx->op_preserve = filegui__check_attrs_on_fs(def_text);
@ -934,11 +933,12 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
fmd_widgets[FMCB21].result = &ctx->dive_into_subdirs; fmd_widgets[FMCB21].result = &ctx->dive_into_subdirs;
/* filter out a possible password from def_text */ /* filter out a possible password from def_text */
def_text_secure = strip_password (g_strdup (def_text), 1); tmp = strip_password (g_strdup (def_text), 1);
if (source_easy_patterns) if (source_easy_patterns)
def_text_secure2 = strutils_glob_escape (def_text_secure); def_text_secure = strutils_glob_escape (tmp);
else else
def_text_secure2 = strutils_regex_escape (def_text_secure); def_text_secure = strutils_regex_escape (tmp);
g_free (tmp);
/* Create the dialog */ /* Create the dialog */
@ -953,18 +953,19 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
Quick_input.i18n = 1; Quick_input.i18n = 1;
Quick_input.widgets = fmd_widgets; Quick_input.widgets = fmd_widgets;
fmd_widgets[FMDI0].text = text; fmd_widgets[FMDI0].text = text;
fmd_widgets[FMDI2].text = def_text_secure2; fmd_widgets[FMDI2].text = def_text_secure;
fmd_widgets[FMDI2].str_result = &dest_dir; fmd_widgets[FMDI2].str_result = &dest_dir;
fmd_widgets[FMDI1].str_result = &source_mask; fmd_widgets[FMDI1].str_result = &source_mask;
*do_background = 0; *do_background = 0;
ask_file_mask:
if ((val = quick_dialog_skip (&Quick_input, SKIP)) == B_CANCEL) { ask_file_mask:
val = quick_dialog_skip (&Quick_input, SKIP);
if (val == B_CANCEL) {
g_free (def_text_secure); g_free (def_text_secure);
return 0; return NULL;
} }
g_free (def_text_secure);
if (ctx->follow_links) if (ctx->follow_links)
ctx->stat_func = mc_stat; ctx->stat_func = mc_stat;
@ -984,8 +985,8 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
} }
if (!dest_dir || !*dest_dir) { if (!dest_dir || !*dest_dir) {
g_free (def_text_secure);
g_free (source_mask); g_free (source_mask);
g_free(def_text_secure2);
return dest_dir; return dest_dir;
} }
@ -994,9 +995,12 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
if (ctx->search_handle == NULL) { if (ctx->search_handle == NULL) {
message (D_ERROR, MSG_ERROR, _("Invalid source pattern `%s'"), message (D_ERROR, MSG_ERROR, _("Invalid source pattern `%s'"),
source_mask); source_mask);
g_free (dest_dir);
g_free (source_mask); g_free (source_mask);
goto ask_file_mask; goto ask_file_mask;
} }
g_free (def_text_secure);
g_free (source_mask); g_free (source_mask);
ctx->search_handle->is_case_sentitive = TRUE; ctx->search_handle->is_case_sentitive = TRUE;
@ -1005,9 +1009,9 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
else else
ctx->search_handle->search_type = MC_SEARCH_T_REGEX; ctx->search_handle->search_type = MC_SEARCH_T_REGEX;
tmpdest = dest_dir; tmp = dest_dir;
dest_dir = tilde_expand(tmpdest); dest_dir = tilde_expand (tmp);
g_free(tmpdest); g_free (tmp);
ctx->dest_mask = strrchr (dest_dir, PATH_SEP); ctx->dest_mask = strrchr (dest_dir, PATH_SEP);
if (ctx->dest_mask == NULL) if (ctx->dest_mask == NULL)
@ -1026,7 +1030,7 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
ctx->dest_mask = g_strdup ("\\0"); ctx->dest_mask = g_strdup ("\\0");
else { else {
ctx->dest_mask = g_strdup (ctx->dest_mask); ctx->dest_mask = g_strdup (ctx->dest_mask);
*orig_mask = 0; *orig_mask = '\0';
} }
if (!*dest_dir) { if (!*dest_dir) {
g_free (dest_dir); g_free (dest_dir);
@ -1035,6 +1039,5 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
if (val == B_USER) if (val == B_USER)
*do_background = 1; *do_background = 1;
g_free(def_text_secure2);
return dest_dir; return dest_dir;
} }