mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-09 13:02:01 +03:00
* ext.c (exec_extension): Use g_free() on the result of
mc_mkstemps(). Don't free it if mc_mkstemps() fails - it's not needed anymore. * user.c (execute_menu_command): Likewise. * util.c (mc_mkstemps): Return NULL in the filename in the case of failure. Remove support for NULL as the first argument. From Andrew V. Samoilov.
This commit is contained in:
parent
f46e633753
commit
a13c1d1928
@ -1,10 +1,20 @@
|
||||
2001-05-22 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* ext.c (exec_extension): Use g_free() on the result of
|
||||
mc_mkstemps(). Don't free it if mc_mkstemps() fails - it's not
|
||||
needed anymore.
|
||||
* user.c (execute_menu_command): Likewise.
|
||||
* util.c (mc_mkstemps): Return NULL in the filename in the case
|
||||
of failure. Remove support for NULL as the first argument.
|
||||
From Andrew V. Samoilov.
|
||||
|
||||
2001-05-21 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* src/ext.c (exec_extension): Use mc_mkstemps().
|
||||
* src/user.c (execute_menu_command): Use mc_mkstemps().
|
||||
* src/util.c (mc_mkstemps): New function - safely create and
|
||||
* ext.c (exec_extension): Use mc_mkstemps().
|
||||
* user.c (execute_menu_command): Use mc_mkstemps().
|
||||
* util.c (mc_mkstemps): New function - safely create and
|
||||
open temporary file. Return the handle and the name.
|
||||
* src/util.h: Declarations for init_tmpdir() and mc_mkstemps().
|
||||
* util.h: Declarations for init_tmpdir() and mc_mkstemps().
|
||||
Define TMPDIR_DEFAULT and SCRIPT_SUFFIX.
|
||||
|
||||
2001-05-18 Pavel Roskin <proski@gnu.org>
|
||||
|
@ -145,7 +145,6 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_
|
||||
if (cmd_file_fd == -1){
|
||||
message (1, MSG_ERROR, _(" Can't create temporary command file \n %s "),
|
||||
unix_error_string (errno));
|
||||
free (file_name);
|
||||
return;
|
||||
}
|
||||
cmd_file = fdopen (cmd_file_fd, "w");
|
||||
@ -166,7 +165,7 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_
|
||||
if (localcopy) {
|
||||
mc_ungetlocalcopy (filename, localcopy, 0);
|
||||
}
|
||||
free (file_name);
|
||||
g_free (file_name);
|
||||
return;
|
||||
}
|
||||
fputs (parameter, cmd_file);
|
||||
@ -210,7 +209,7 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_
|
||||
if (localcopy == NULL) {
|
||||
fclose(cmd_file);
|
||||
unlink(file_name);
|
||||
free (file_name);
|
||||
g_free (file_name);
|
||||
return;
|
||||
}
|
||||
mc_stat (localcopy, &mystat);
|
||||
@ -318,7 +317,7 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_
|
||||
mc_stat (localcopy, &mystat);
|
||||
mc_ungetlocalcopy (filename, localcopy, localmtime != mystat.st_mtime);
|
||||
}
|
||||
free (file_name);
|
||||
g_free (file_name);
|
||||
}
|
||||
|
||||
#ifdef FILE_L
|
||||
|
@ -545,7 +545,6 @@ execute_menu_command (char *commands)
|
||||
if (cmd_file_fd == -1){
|
||||
message (1, MSG_ERROR, _(" Can't create temporary command file \n %s "),
|
||||
unix_error_string (errno));
|
||||
free (file_name);
|
||||
return;
|
||||
}
|
||||
cmd_file = fdopen (cmd_file_fd, "w");
|
||||
@ -570,7 +569,7 @@ execute_menu_command (char *commands)
|
||||
/* User canceled */
|
||||
fclose (cmd_file);
|
||||
unlink (file_name);
|
||||
free (file_name);
|
||||
g_free (file_name);
|
||||
return;
|
||||
}
|
||||
if (do_quote) {
|
||||
@ -611,7 +610,7 @@ execute_menu_command (char *commands)
|
||||
chmod (file_name, S_IRWXU);
|
||||
execute (file_name);
|
||||
unlink (file_name);
|
||||
free (file_name);
|
||||
g_free (file_name);
|
||||
}
|
||||
|
||||
/*
|
||||
|
17
src/util.c
17
src/util.c
@ -1288,9 +1288,10 @@ typedef unsigned long gcc_uint64_t;
|
||||
|
||||
/*
|
||||
* Arguments:
|
||||
* pname - if not NULL, put the filename here.
|
||||
* prefix - filename only, temporary directory is prepended.
|
||||
* suffix - if not NULL, appended after the random part.
|
||||
* pname (output) - pointer to the name of the temp file (needs g_free).
|
||||
* NULL if the function fails.
|
||||
* prefix - part of the filename before the random part (without directory).
|
||||
* suffix - if not NULL, part of the filename after the random part.
|
||||
*
|
||||
* Result:
|
||||
* handle of the open file or -1 if couldn't open any.
|
||||
@ -1316,7 +1317,6 @@ int mc_mkstemps(char **pname, const char *prefix, const char *suffix)
|
||||
tmpbase = concat_dir_and_file (tmpdir, prefix);
|
||||
|
||||
tmpname = g_strconcat (tmpbase, "XXXXXX", suffix, NULL);
|
||||
if (pname)
|
||||
*pname = tmpname;
|
||||
XXXXXX = &tmpname[strlen (tmpbase)];
|
||||
g_free(tmpbase);
|
||||
@ -1345,8 +1345,6 @@ int mc_mkstemps(char **pname, const char *prefix, const char *suffix)
|
||||
fd = open (tmpname, O_RDWR|O_CREAT|O_EXCL, 0600);
|
||||
if (fd >= 0) {
|
||||
/* Successfully created. */
|
||||
if (!pname)
|
||||
g_free (tmpname);
|
||||
return fd;
|
||||
}
|
||||
|
||||
@ -1356,12 +1354,9 @@ int mc_mkstemps(char **pname, const char *prefix, const char *suffix)
|
||||
value += 7777;
|
||||
}
|
||||
|
||||
/* We return the null string if we can't find a unique file name.
|
||||
Of course, only if the caller wants any string. */
|
||||
if (!pname)
|
||||
/* Unsuccessful. Free the filename. */
|
||||
g_free (tmpname);
|
||||
else
|
||||
tmpname[0] = '\0';
|
||||
tmpname = NULL;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user