Skip to content

Commit

Permalink
Fix memory leak in layout_menu_kbd_map_cb()
Browse files Browse the repository at this point in the history
Simplify a bit.
  • Loading branch information
qarkai authored and caclark committed Dec 28, 2024
1 parent ff74099 commit 0e82c56
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/layout-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,6 @@ static void layout_menu_foreach_func(
static void layout_menu_kbd_map_cb(GtkAction *, gpointer)
{
gint fd = -1;
GPtrArray *array;
char * tmp_file;
GError *error = nullptr;
GIOChannel *channel;
Expand All @@ -1468,7 +1467,6 @@ static void layout_menu_kbd_map_cb(GtkAction *, gpointer)
const char *key_name;
char *converted_line;
int keymap_index;
guint index;

fd = g_file_open_tmp("geeqie_keymap_XXXXXX.svg", &tmp_file, &error);
if (error)
Expand All @@ -1478,7 +1476,7 @@ static void layout_menu_kbd_map_cb(GtkAction *, gpointer)
}
else
{
array = g_ptr_array_new();
GPtrArray *array = g_ptr_array_new_with_free_func(g_free);

gtk_accel_map_foreach(array, layout_menu_foreach_func);

Expand All @@ -1492,9 +1490,8 @@ static void layout_menu_kbd_map_cb(GtkAction *, gpointer)
pre_key = g_strsplit(keymap_template[keymap_index],">key:",2);
post_key = g_strsplit(pre_key[1],"<",2);

index=0;
key_name = " ";
for (index=0; index < array->len-2; index=index+2)
for (guint index = 0; index < array->len-1; index += 2)
{
if (!(g_ascii_strcasecmp(static_cast<const gchar *>(g_ptr_array_index(array,index+1)), post_key[0])))
{
Expand Down Expand Up @@ -1534,12 +1531,6 @@ static void layout_menu_kbd_map_cb(GtkAction *, gpointer)
if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
g_io_channel_unref(channel);

index=0;
for (index=0; index < array->len-2; index=index+2)
{
g_free(g_ptr_array_index(array,index));
g_free(g_ptr_array_index(array,index+1));
}
g_ptr_array_unref(array);

view_window_new(file_data_new_simple(tmp_file));
Expand Down

0 comments on commit 0e82c56

Please sign in to comment.