Update utils_free_pointers().

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3246 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2008-11-18 17:24:10 +00:00
parent a2ceb60e3a
commit 484f1ea9ab
2 changed files with 16 additions and 17 deletions

View File

@ -1,4 +1,4 @@
2008-11-16 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> 2008-11-18 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/notebook.c: * src/notebook.c:
Remove forced size requests for the tab close icon as it seems not Remove forced size requests for the tab close icon as it seems not
@ -17,6 +17,8 @@
src/project.c, src/search.c, src/editor.c: src/project.c, src/search.c, src/editor.c:
Make utils_free_pointers() take an arg_count argument to prevent Make utils_free_pointers() take an arg_count argument to prevent
memory leaks. memory leaks.
* plugins/classbuilder.c:
Update utils_free_pointers().
2008-11-16 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> 2008-11-16 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

View File

@ -223,27 +223,24 @@ static void cc_dlg_on_base_name_entry_changed(GtkWidget *entry, CreateClassDialo
static void cc_dlg_on_create_class(CreateClassDialog *cc_dlg); static void cc_dlg_on_create_class(CreateClassDialog *cc_dlg);
/* I don't want this to be in the plugin API because it can cause leaks if any pointers /* The list must be ended with NULL as an extra check that arg_count is correct. */
* are NULL -ntrel. */
/* Frees all passed pointers if they are *ALL* non-NULL.
* Do not use if any pointers may be NULL.
* The first argument is nothing special, it will also be freed.
* The list must be ended with NULL. */
static void static void
utils_free_pointers(gpointer first, ...) utils_free_pointers(gsize arg_count, ...)
{ {
va_list a; va_list a;
gpointer sa; gsize i;
gpointer ptr;
for (va_start(a, first); (sa = va_arg(a, gpointer), sa!=NULL);) va_start(a, arg_count);
{ for (i = 0; i < arg_count; i++)
if (sa != NULL) {
g_free(sa); ptr = va_arg(a, gpointer);
g_free(ptr);
} }
ptr = va_arg(a, gpointer);
if (ptr)
g_warning("Wrong arg_count!");
va_end(a); va_end(a);
if (first != NULL)
g_free(first);
} }
@ -748,7 +745,7 @@ static void cc_dlg_on_create_class(CreateClassDialog *cc_dlg)
g_free(text); g_free(text);
} }
utils_free_pointers(tmp, class_info->class_name, class_info->class_name_up, utils_free_pointers(17, tmp, class_info->class_name, class_info->class_name_up,
class_info->base_name, class_info->class_name_low, class_info->base_include, class_info->base_name, class_info->class_name_low, class_info->base_include,
class_info->header, class_info->header_guard, class_info->source, class_info->base_decl, class_info->header, class_info->header_guard, class_info->source, class_info->base_decl,
class_info->constructor_decl, class_info->constructor_impl, class_info->constructor_decl, class_info->constructor_impl,