Massive use of MC_PTR_FREE macro.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2014-08-05 11:18:30 +04:00
parent de026dd1fc
commit 6d82155270
35 changed files with 85 additions and 182 deletions

View File

@ -104,8 +104,7 @@ mc_fhl_free (mc_fhl_t ** fhl)
mc_fhl_clear (*fhl);
g_free (*fhl);
*fhl = NULL;
MC_PTR_FREE (*fhl);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -168,10 +168,8 @@ mc_config_init_one_config_path (const char *path_base, const char *subdir, GErro
mc_config_mkdir (full_path, mcerror);
if (mcerror != NULL && *mcerror != NULL)
{
g_free (full_path);
full_path = NULL;
}
MC_PTR_FREE (full_path);
return full_path;
}

View File

@ -33,6 +33,7 @@
#include "lib/global.h"
#include "lib/strutil.h"
#include "lib/search.h"
#include "lib/util.h"
#ifdef HAVE_CHARSET
#include "lib/charsets.h"
#endif
@ -273,8 +274,7 @@ mc_search_run (mc_search_t * lc_mc_search, const void *user_data,
#endif /* SEARCH_TYPE_GLIB */
lc_mc_search->error = MC_SEARCH_E_OK;
g_free (lc_mc_search->error_str);
lc_mc_search->error_str = NULL;
MC_PTR_FREE (lc_mc_search->error_str);
if ((lc_mc_search->conditions == NULL) && !mc_search_prepare (lc_mc_search))
return FALSE;

View File

@ -168,13 +168,11 @@ mc_skin_deinit (void)
tty_color_free_all_tmp ();
tty_color_free_all_non_tmp ();
g_free (mc_skin__default.name);
mc_skin__default.name = NULL;
MC_PTR_FREE (mc_skin__default.name);
g_hash_table_destroy (mc_skin__default.colors);
mc_skin__default.colors = NULL;
g_free (mc_skin__default.description);
mc_skin__default.description = NULL;
MC_PTR_FREE (mc_skin__default.description);
mc_config_deinit (mc_skin__default.config);
mc_skin__default.config = NULL;

View File

@ -135,8 +135,7 @@ resolve_symlinks (const vfs_path_t * vpath)
*q = 0;
if (mc_lstat (vpath, &mybuf) < 0)
{
g_free (buf);
buf = NULL;
MC_PTR_FREE (buf);
goto ret;
}
if (!S_ISLNK (mybuf.st_mode))
@ -148,8 +147,7 @@ resolve_symlinks (const vfs_path_t * vpath)
len = mc_readlink (vpath, buf2, MC_MAXPATHLEN - 1);
if (len < 0)
{
g_free (buf);
buf = NULL;
MC_PTR_FREE (buf);
goto ret;
}
buf2[len] = 0;

View File

@ -963,8 +963,7 @@ vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent)
if (ent->dir != NULL)
ent->dir->subdir = g_list_remove (ent->dir->subdir, ent);
g_free (ent->name);
/* ent->name = NULL; */
MC_PTR_FREE (ent->name);
if (ent->ino != NULL)
{
@ -1405,8 +1404,7 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino)
close (handle);
unlink (ino->localname);
error_4:
g_free (ino->localname);
ino->localname = NULL;
MC_PTR_FREE (ino->localname);
g_free (fh.data);
return -1;
}

View File

@ -39,6 +39,7 @@
#include "lib/tty/tty.h"
#include "lib/tty/color.h"
#include "lib/skin.h"
#include "lib/util.h"
#include "lib/widget.h"
/*** global variables ****************************************************************************/
@ -120,8 +121,7 @@ groupbox_new (int y, int x, int height, int width, const char *title)
void
groupbox_set_title (WGroupbox * g, const char *title)
{
g_free (g->title);
g->title = NULL;
MC_PTR_FREE (g->title);
/* Strip existing spaces, add one space before and after the title */
if (title != NULL && *title != '\0')

View File

@ -890,9 +890,7 @@ input_destroy (WInput * in)
}
g_free (in->history.name);
g_free (in->buffer);
g_free (kill_buffer);
kill_buffer = NULL;
MC_PTR_FREE (kill_buffer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -270,14 +270,11 @@ filename_completion_function (const char *text, int state, input_complete_t flag
mc_closedir (directory);
directory = NULL;
}
g_free (dirname);
dirname = NULL;
MC_PTR_FREE (dirname);
vfs_path_free (dirname_vpath);
dirname_vpath = NULL;
g_free (filename);
filename = NULL;
g_free (users_dirname);
users_dirname = NULL;
MC_PTR_FREE (filename);
MC_PTR_FREE (users_dirname);
return NULL;
}
@ -660,18 +657,12 @@ command_completion_function (const char *_text, int state, input_complete_t flag
}
found = filename_completion_function (cur_word, state - init_state, flags);
if (!found)
{
g_free (cur_word);
cur_word = NULL;
}
MC_PTR_FREE (cur_word);
}
}
if (found == NULL)
{
g_free (path);
path = NULL;
}
MC_PTR_FREE (path);
else
{
p = strrchr (found, PATH_SEP);
@ -795,11 +786,9 @@ completion_matches (const char *text, CompletionFunction entry_function, input_c
match_list[0] = g_strndup (match_list[1], low);
}
}
else
{ /* There were no matches. */
g_free (match_list);
match_list = NULL;
}
else /* There were no matches. */
MC_PTR_FREE (match_list);
return match_list;
}

View File

@ -330,17 +330,10 @@ static gchar *mc_args__loc__usage_string = NULL;
static void
mc_args_clean_temp_help_strings (void)
{
g_free (mc_args__loc__colors_string);
mc_args__loc__colors_string = NULL;
g_free (mc_args__loc__footer_string);
mc_args__loc__footer_string = NULL;
g_free (mc_args__loc__header_string);
mc_args__loc__header_string = NULL;
g_free (mc_args__loc__usage_string);
mc_args__loc__usage_string = NULL;
MC_PTR_FREE (mc_args__loc__colors_string);
MC_PTR_FREE (mc_args__loc__footer_string);
MC_PTR_FREE (mc_args__loc__header_string);
MC_PTR_FREE (mc_args__loc__usage_string);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -1858,8 +1858,7 @@ destroy_hdiff (WDiff * dview)
mc_search_free (dview->search.handle);
dview->search.handle = NULL;
g_free (dview->search.last_string);
dview->search.last_string = NULL;
MC_PTR_FREE (dview->search.last_string);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -238,10 +238,8 @@ book_mark_clear (WEdit * edit, long line, int c)
}
/* if there is only our dummy book mark left, clear it for speed */
if (edit->book_mark->line == -1 && edit->book_mark->next == NULL)
{
g_free (edit->book_mark);
edit->book_mark = NULL;
}
MC_PTR_FREE (edit->book_mark);
return r;
}
@ -271,10 +269,7 @@ book_mark_flush (WEdit * edit, int c)
}
}
if (edit->book_mark->next == NULL)
{
g_free (edit->book_mark);
edit->book_mark = NULL;
}
MC_PTR_FREE (edit->book_mark);
edit->force |= REDRAW_PAGE;
}

View File

@ -357,8 +357,7 @@ check_file_access (WEdit * edit, const vfs_path_t * filename_vpath, struct stat
errmsg = g_strdup_printf (_("File \"%s\" is too large.\nOpen it anyway?"),
vfs_path_as_str (filename_vpath));
act = edit_query_dialog2 (_("Warning"), errmsg, _("&Yes"), _("&No"));
g_free (errmsg);
errmsg = NULL;
MC_PTR_FREE (errmsg);
if (act != 0)
ret = FALSE;

View File

@ -2017,16 +2017,14 @@ edit_load_macro_cmd (WEdit * edit)
else
{
m_act.action = keybind_lookup_action (macro_pair[0]);
g_free (macro_pair[0]);
macro_pair[0] = NULL;
MC_PTR_FREE (macro_pair[0]);
}
if (macro_pair[1] == NULL || macro_pair[1][0] == '\0')
m_act.ch = -1;
else
{
m_act.ch = strtol (macro_pair[1], NULL, 0);
g_free (macro_pair[1]);
macro_pair[1] = NULL;
MC_PTR_FREE (macro_pair[1]);
}
if (m_act.action != 0)
{
@ -2516,8 +2514,8 @@ edit_replace_cmd (WEdit * edit, int again)
if (edit == NULL)
{
g_free (saved1), saved1 = NULL;
g_free (saved2), saved2 = NULL;
MC_PTR_FREE (saved1);
MC_PTR_FREE (saved2);
return;
}
@ -2799,8 +2797,7 @@ edit_search_cmd (WEdit * edit, gboolean again)
if (edit->search == NULL)
{
/* if not... then ask for an expression */
g_free (edit->last_search_string);
edit->last_search_string = NULL;
MC_PTR_FREE (edit->last_search_string);
edit_search (edit);
}
else
@ -2820,8 +2817,7 @@ edit_search_cmd (WEdit * edit, gboolean again)
else
{
/* if not... then ask for an expression */
g_free (edit->last_search_string);
edit->last_search_string = NULL;
MC_PTR_FREE (edit->last_search_string);
edit_search (edit);
}
}

View File

@ -298,8 +298,7 @@ aspell_init (void)
if (!spell_available ())
{
g_free (global_speller);
global_speller = NULL;
MC_PTR_FREE (global_speller);
return;
}
@ -338,8 +337,7 @@ aspell_clean (void)
if (global_speller->config != NULL)
mc_delete_aspell_config (global_speller->config);
g_free (global_speller);
global_speller = NULL;
MC_PTR_FREE (global_speller);
g_module_close (spell_module);
spell_module = NULL;

View File

@ -537,8 +537,7 @@ dir_list_clean (dir_list * list)
file_entry_t *fentry;
fentry = &list->list[i];
g_free (fentry->fname);
fentry->fname = NULL;
MC_PTR_FREE (fentry->fname);
}
list->len = 0;

View File

@ -747,8 +747,7 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c
void
flush_extension_file (void)
{
g_free (data);
data = NULL;
MC_PTR_FREE (data);
}
/* --------------------------------------------------------------------------------------------- */
@ -828,8 +827,7 @@ regex_command_for (void *target, const vfs_path_t * filename_vpath, const char *
if (strstr (data, "regex/") == NULL && strstr (data, "shell/") == NULL &&
strstr (data, "type/") == NULL)
{
g_free (data);
data = NULL;
MC_PTR_FREE (data);
if (!mc_user_ext)
{

View File

@ -3077,8 +3077,7 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
#endif /* WITH_FULL_PATHS */
g_free (dest);
vfs_path_free (dest_vpath);
g_free (ctx->dest_mask);
ctx->dest_mask = NULL;
MC_PTR_FREE (ctx->dest_mask);
#ifdef ENABLE_BACKGROUND
/* Let our parent know we are saying bye bye */

View File

@ -862,8 +862,7 @@ file_op_context_destroy_ui (file_op_context_t * ctx)
dlg_run_done (ui->op_dlg);
dlg_destroy (ui->op_dlg);
g_free (ui);
ctx->ui = NULL;
MC_PTR_FREE (ctx->ui);
}
}

View File

@ -265,10 +265,7 @@ parse_ignore_dirs (const char *ignore_dirs)
if (find_ignore_dirs[w][0] != '\0')
w++;
else
{
g_free (find_ignore_dirs[w]);
find_ignore_dirs[w] = NULL;
}
MC_PTR_FREE (find_ignore_dirs[w]);
}
if (find_ignore_dirs[0] == NULL)
@ -315,10 +312,7 @@ find_load_options (void)
options.ignore_dirs = mc_config_get_string (mc_main_config, "FindFile", "ignore_dirs", "");
if (options.ignore_dirs[0] == '\0')
{
g_free (options.ignore_dirs);
options.ignore_dirs = NULL;
}
MC_PTR_FREE (options.ignore_dirs);
}
/* --------------------------------------------------------------------------------------------- */
@ -1251,8 +1245,7 @@ do_search (WDialog * h)
mc_closedir (dirp);
dirp = NULL;
}
g_free (directory);
directory = NULL;
MC_PTR_FREE (directory);
dp = NULL;
return 1;
}
@ -1386,8 +1379,7 @@ do_search (WDialog * h)
static void
init_find_vars (void)
{
g_free (old_dir);
old_dir = NULL;
MC_PTR_FREE (old_dir);
matches = 0;
ignore_count = 0;
@ -1813,8 +1805,7 @@ do_find (const char *start_dir, ssize_t start_dir_len, const char *ignore_dirs,
g_free (content_pattern);
kill_gui ();
do_search (NULL); /* force do_search to release resources */
g_free (old_dir);
old_dir = NULL;
MC_PTR_FREE (old_dir);
rotate_dash (FALSE);
return return_value;

View File

@ -1663,14 +1663,12 @@ done_hotlist (void)
remove_group (hotlist);
g_free (hotlist->label);
g_free (hotlist->directory);
g_free (hotlist);
hotlist = NULL;
MC_PTR_FREE (hotlist);
}
hotlist_state.loaded = FALSE;
g_free (hotlist_file_name);
hotlist_file_name = NULL;
MC_PTR_FREE (hotlist_file_name);
l_hotlist = NULL;
current_group = NULL;

View File

@ -4694,8 +4694,7 @@ remove_encoding_from_path (const vfs_path_t * vpath)
continue;
}
g_free (path_element->encoding);
path_element->encoding = NULL;
MC_PTR_FREE (path_element->encoding);
str_vfs_convert_from (converter, path_element->path, tmp_conv);

View File

@ -894,8 +894,7 @@ tree_store_end_check (void)
}
/* get the stuff in the scan order */
ts.add_queue_vpath = g_list_reverse (ts.add_queue_vpath);
the_queue = ts.add_queue_vpath;
the_queue = g_list_reverse (ts.add_queue_vpath);
ts.add_queue_vpath = NULL;
vfs_path_free (ts.check_name);
ts.check_name = NULL;

View File

@ -321,8 +321,7 @@ debug_out (char *start, char *end, int cond)
}
debug_flag = 0;
g_free (msg);
msg = NULL;
MC_PTR_FREE (msg);
}
else
{
@ -946,8 +945,7 @@ user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_e
{
message (D_ERROR, MSG_ERROR, _("Cannot open file %s\n%s"), menu,
unix_error_string (errno));
g_free (menu);
menu = NULL;
MC_PTR_FREE (menu);
return FALSE;
}
@ -984,8 +982,7 @@ user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_e
if (!g_file_get_contents (menu, &data, NULL, NULL))
{
message (D_ERROR, MSG_ERROR, _("Cannot open file%s\n%s"), menu, unix_error_string (errno));
g_free (menu);
menu = NULL;
MC_PTR_FREE (menu);
return FALSE;
}
@ -1124,8 +1121,7 @@ user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_e
}
easy_patterns = old_patterns;
g_free (menu);
menu = NULL;
MC_PTR_FREE (menu);
g_free (entries);
g_free (data);
return res;

View File

@ -95,10 +95,7 @@ learn_button (WButton * button, int action)
"and wait as well."), _(key_name_conv_tab[action - B_USER].longname));
mc_refresh ();
if (learnkeys[action - B_USER].sequence != NULL)
{
g_free (learnkeys[action - B_USER].sequence);
learnkeys[action - B_USER].sequence = NULL;
}
MC_PTR_FREE (learnkeys[action - B_USER].sequence);
seq = learn_key ();
if (seq != NULL)

View File

@ -206,8 +206,7 @@ cpio_free_archive (struct vfs_class *me, struct vfs_s_super *super)
arch->fd = -1;
g_slist_free_full (arch->deferred, g_free);
arch->deferred = NULL;
g_free (super->data);
super->data = NULL;
MC_PTR_FREE (super->data);
}
/* --------------------------------------------------------------------------------------------- */
@ -250,8 +249,7 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super, const vfs_
{
message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), s);
g_free (s);
g_free (super->name);
super->name = NULL;
MC_PTR_FREE (super->name);
return -1;
}
g_free (s);

View File

@ -1489,10 +1489,7 @@ static void
fish_fh_free_data (vfs_file_handler_t * fh)
{
if (fh != NULL)
{
g_free (fh->data);
fh->data = NULL;
}
MC_PTR_FREE (fh->data);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -355,10 +355,7 @@ ftpfs_correct_url_parameters (const vfs_path_element_t * velement)
/* If user is different, remove password */
if (new_user != NULL && strcmp (path_element->user, new_user) != 0)
{
g_free (path_element->password);
path_element->password = NULL;
}
MC_PTR_FREE (path_element->password);
g_free (new_user);
g_free (new_passwd);
@ -552,8 +549,7 @@ ftpfs_free_archive (struct vfs_class *me, struct vfs_s_super *super)
close (SUP->sock);
}
g_free (SUP->current_dir);
g_free (super->data);
super->data = NULL;
MC_PTR_FREE (super->data);
}
/* --------------------------------------------------------------------------------------------- */
@ -887,8 +883,7 @@ ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super)
}
vfs_print_message (_("ftpfs: making connection to %s"), host);
g_free (host);
host = NULL;
MC_PTR_FREE (host);
if (connect (my_socket, curr_res->ai_addr, curr_res->ai_addrlen) >= 0)
break;
@ -2119,10 +2114,7 @@ static void
ftpfs_fh_free_data (vfs_file_handler_t * fh)
{
if (fh != NULL)
{
g_free (fh->data);
fh->data = NULL;
}
MC_PTR_FREE (fh->data);
}
/* --------------------------------------------------------------------------------------------- */
@ -2189,8 +2181,7 @@ ftpfs_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t
if (fh->ino->localname)
{
unlink (fh->ino->localname);
g_free (fh->ino->localname);
fh->ino->localname = NULL;
MC_PTR_FREE (fh->ino->localname);
}
return 0;
}
@ -2421,10 +2412,8 @@ ftpfs_netrc_lookup (const char *host, char **login, char **pass)
} *rup_cache = NULL, *rupp;
/* Initialize *login and *pass */
g_free (*login);
*login = NULL;
g_free (*pass);
*pass = NULL;
MC_PTR_FREE (*login);
MC_PTR_FREE (*pass);
/* Look up in the cache first */
for (rupp = rup_cache; rupp != NULL; rupp = rupp->next)

View File

@ -505,9 +505,8 @@ sfs_done (struct vfs_class *me)
for (i = 0; i < sfs_no; i++)
{
g_free (sfs_prefix[i]);
g_free (sfs_command[i]);
sfs_prefix[i] = sfs_command[i] = NULL;
MC_PTR_FREE (sfs_prefix[i]);
MC_PTR_FREE (sfs_command[i]);
}
sfs_no = 0;
}

View File

@ -320,8 +320,7 @@ tar_open_archive_int (struct vfs_class *me, const vfs_path_t * vpath, struct vfs
g_free (s);
if (result == -1)
{
g_free (archive->name);
archive->name = NULL;
MC_PTR_FREE (archive->name);
ERRNOR (ENOENT, -1);
}
}
@ -585,8 +584,7 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive, int tard, si
data = tar_get_next_record (archive, tard)->charptr;
if (data == NULL)
{
g_free (*longp);
*longp = NULL;
MC_PTR_FREE (*longp);
message (D_ERROR, MSG_ERROR, _("Unexpected EOF on archive file"));
return STATUS_BADCHECKSUM;
}
@ -600,8 +598,7 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive, int tard, si
if (bp - *longp == MC_MAXPATHLEN && bp[-1] != '\0')
{
g_free (*longp);
*longp = NULL;
MC_PTR_FREE (*longp);
message (D_ERROR, MSG_ERROR, _("Inconsistent tar archive"));
return STATUS_BADCHECKSUM;
}

View File

@ -63,6 +63,7 @@
#include "lib/global.h"
#include "lib/util.h"
#include "lib/widget.h" /* message() */
#include "lib/vfs/utilvfs.h"
#include "lib/vfs/vfs.h"
@ -140,12 +141,9 @@ undelfs_shutdown (void)
if (fs)
ext2fs_close (fs);
fs = NULL;
g_free (ext2_fname);
ext2_fname = NULL;
g_free (delarray);
delarray = NULL;
g_free (block_buf);
block_buf = NULL;
MC_PTR_FREE (ext2_fname);
MC_PTR_FREE (delarray);
MC_PTR_FREE (block_buf);
}
/* --------------------------------------------------------------------------------------------- */
@ -328,11 +326,9 @@ undelfs_loaddel (void)
error_out:
ext2fs_close_inode_scan (scan);
free_block_buf:
g_free (block_buf);
block_buf = NULL;
MC_PTR_FREE (block_buf);
free_delarray:
g_free (delarray);
delarray = NULL;
MC_PTR_FREE (delarray);
return 0;
}

View File

@ -154,8 +154,7 @@ mcview_continue_search_cmd (mcview_t * view)
if (view->search == NULL)
{
/* if not... then ask for an expression */
g_free (view->last_search_string);
view->last_search_string = NULL;
MC_PTR_FREE (view->last_search_string);
mcview_search (view, TRUE);
}
else
@ -175,8 +174,7 @@ mcview_continue_search_cmd (mcview_t * view)
else
{
/* if not... then ask for an expression */
g_free (view->last_search_string);
view->last_search_string = NULL;
MC_PTR_FREE (view->last_search_string);
mcview_search (view, TRUE);
}
}

View File

@ -368,12 +368,10 @@ mcview_close_datasource (mcview_t * view)
case DS_FILE:
(void) mc_close (view->ds_file_fd);
view->ds_file_fd = -1;
g_free (view->ds_file_data);
view->ds_file_data = NULL;
MC_PTR_FREE (view->ds_file_data);
break;
case DS_STRING:
g_free (view->ds_string_data);
view->ds_string_data = NULL;
MC_PTR_FREE (view->ds_string_data);
break;
default:
#ifdef HAVE_ASSERT_H

View File

@ -224,8 +224,7 @@ mcview_done (mcview_t * view)
view->filename_vpath = NULL;
vfs_path_free (view->workdir_vpath);
view->workdir_vpath = NULL;
g_free (view->command);
view->command = NULL;
MC_PTR_FREE (view->command);
mcview_close_datasource (view);
/* the growing buffer is freed with the datasource */

View File

@ -319,8 +319,7 @@ mcview_nroff_seq_free (mcview_nroff_t ** nroff)
{
if (nroff == NULL || *nroff == NULL)
return;
g_free (*nroff);
*nroff = NULL;
MC_PTR_FREE (*nroff);
}
/* --------------------------------------------------------------------------------------------- */