From a13c1d19286acfc9bd0abf7b69c6ee06a72cd09b Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 22 May 2001 07:10:43 +0000 Subject: [PATCH] * 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. --- src/ChangeLog | 18 ++++++++++++++---- src/ext.c | 7 +++---- src/user.c | 5 ++--- src/util.c | 21 ++++++++------------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 0c0025232..599297136 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,10 +1,20 @@ +2001-05-22 Pavel Roskin + + * 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 - * 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 diff --git a/src/ext.c b/src/ext.c index b13eea949..041fd48d0 100644 --- a/src/ext.c +++ b/src/ext.c @@ -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 diff --git a/src/user.c b/src/user.c index c1fddb595..514fdef10 100644 --- a/src/user.c +++ b/src/user.c @@ -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); } /* diff --git a/src/util.c b/src/util.c index aeed05962..86cdc28bb 100644 --- a/src/util.c +++ b/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,8 +1317,7 @@ 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; + *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) - g_free (tmpname); - else - tmpname[0] = '\0'; + /* Unsuccessful. Free the filename. */ + g_free (tmpname); + tmpname = NULL; return -1; }