Fix usage of shell_[un]escape functions.

These functions returns newly allocated string, but calling don't freeze correctly allocated memory.
This commit is contained in:
Slava Zanko 2009-05-27 00:14:08 +03:00
parent 9e325ad1b0
commit 1a899905bd
4 changed files with 40 additions and 13 deletions

View File

@ -59,15 +59,15 @@ WInput *cmdline;
* they want the behavior they are used to in the shell. * they want the behavior they are used to in the shell.
*/ */
static int static int
examine_cd (char *path) examine_cd (const char *_path)
{ {
int result, qlen; int result, qlen;
char *path_tilde; char *path_tilde, *path;
char *p, *q, *r, *s, c; char *p, *q, *r, *s, c;
const char *t; const char *t;
/* Tilde expansion */ /* Tilde expansion */
path = shell_unescape(path); path = shell_unescape(_path);
path_tilde = tilde_expand (path); path_tilde = tilde_expand (path);
/* Leave space for further expansion */ /* Leave space for further expansion */
@ -139,6 +139,7 @@ examine_cd (char *path)
} }
g_free (q); g_free (q);
g_free (path_tilde); g_free (path_tilde);
g_free (path);
return result; return result;
} }

View File

@ -73,8 +73,9 @@ static const char * show_c_flags(INPUT_COMPLETE_FLAGS flags)
#endif /* DO_CMPLETION_DEBUG */ #endif /* DO_CMPLETION_DEBUG */
static char * static char *
filename_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags) filename_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS flags)
{ {
char *text;
static DIR *directory; static DIR *directory;
static char *filename = NULL; static char *filename = NULL;
static char *dirname = NULL; static char *dirname = NULL;
@ -87,7 +88,7 @@ filename_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
SHOW_C_CTX("filename_completion_function"); SHOW_C_CTX("filename_completion_function");
if (text && (flags & INPUT_COMPLETE_SHELL_ESC)) if (text && (flags & INPUT_COMPLETE_SHELL_ESC))
text = shell_unescape (text); text = shell_unescape (_text);
/* If we're starting the match process, initialize us a bit. */ /* If we're starting the match process, initialize us a bit. */
if (!state){ if (!state){
@ -214,8 +215,11 @@ filename_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
if (temp && (flags & INPUT_COMPLETE_SHELL_ESC)) if (temp && (flags & INPUT_COMPLETE_SHELL_ESC))
{ {
char *temp2 = temp;
temp = shell_escape(temp); temp = shell_escape(temp);
g_free(temp2);
} }
g_free(text);
return temp; return temp;
} }
} }
@ -448,8 +452,9 @@ hostname_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
* table of shell built-ins. * table of shell built-ins.
*/ */
static char * static char *
command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags) command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS flags)
{ {
char *text;
static const char *path_end; static const char *path_end;
static int isabsolute; static int isabsolute;
static int phase; static int phase;
@ -478,8 +483,7 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
if (!(flags & INPUT_COMPLETE_COMMANDS)) if (!(flags & INPUT_COMPLETE_COMMANDS))
return 0; return 0;
text = shell_unescape(_text);
text = shell_unescape(text);
flags &= ~INPUT_COMPLETE_SHELL_ESC; flags &= ~INPUT_COMPLETE_SHELL_ESC;
if (!state) { /* Initialize us a little bit */ if (!state) { /* Initialize us a little bit */
@ -499,10 +503,16 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
} }
if (isabsolute) { if (isabsolute) {
char *temp_p;
p = filename_completion_function (text, state, flags); p = filename_completion_function (text, state, flags);
if (!p) if (!p){
g_free(text);
return 0; return 0;
}
temp_p = p;
p = shell_escape(p); p = shell_escape(p);
g_free(temp_p);
g_free(text);
return p; return p;
} }
@ -554,14 +564,19 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
if (!found) { if (!found) {
g_free (path); g_free (path);
path = NULL; path = NULL;
g_free(text);
return NULL; return NULL;
} }
if ((p = strrchr (found, PATH_SEP)) != NULL) { if ((p = strrchr (found, PATH_SEP)) != NULL) {
p++; p++;
g_free(found);
found = p;
p = shell_escape(p); p = shell_escape(p);
g_free(found); g_free(found);
g_free(text);
return p; return p;
} }
g_free(text);
return found; return found;
} }

View File

@ -2118,9 +2118,14 @@ panel_operate (void *source_panel, FileOperation operation,
value = transform_error; value = transform_error;
else { else {
char *temp2 = concat_dir_and_file (dest, temp); char *temp2 = concat_dir_and_file (dest, temp);
char *temp3;
temp3 = source_with_path;
source_with_path = shell_unescape(source_with_path); source_with_path = shell_unescape(source_with_path);
g_free(temp3);
temp3 = temp2;
temp2 = shell_unescape(temp2); temp2 = shell_unescape(temp2);
g_free(temp3);
switch (operation) { switch (operation) {
case OP_COPY: case OP_COPY:

View File

@ -508,6 +508,7 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
switch(buffer[0]) { switch(buffer[0]) {
case ':': { case ':': {
char *temp;
char *data_start = buffer+1; char *data_start = buffer+1;
char *filename = data_start; char *filename = data_start;
char *linkname = data_start; char *linkname = data_start;
@ -542,10 +543,14 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
} }
ent->name = str_dup_range(filename, filename_bound); ent->name = str_dup_range(filename, filename_bound);
shell_unescape(ent->name); temp = ent->name;
ent->name = shell_unescape(ent->name);
g_free(temp);
ent->ino->linkname = str_dup_range(linkname, linkname_bound); ent->ino->linkname = str_dup_range(linkname, linkname_bound);
shell_unescape(ent->ino->linkname); temp = ent->ino->linkname;
ent->ino->linkname = shell_unescape(ent->ino->linkname);
g_free(temp);
} else { } else {
/* we expect: "escaped-name" */ /* we expect: "escaped-name" */
if (filename_bound - filename > 2) if (filename_bound - filename > 2)
@ -559,9 +564,10 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
if (*(filename_bound - 1) == '"') if (*(filename_bound - 1) == '"')
--filename_bound; --filename_bound;
} }
ent->name = str_dup_range(filename, filename_bound); ent->name = str_dup_range(filename, filename_bound);
shell_unescape(ent->name); temp = ent->name;
ent->name = shell_unescape(ent->name);
g_free(temp);
} }
break; break;
} }