Skip to content

Commit

Permalink
Fix more memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tatokis committed Nov 21, 2022
1 parent 0873aa5 commit 0a3a923
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
9 changes: 5 additions & 4 deletions src/alarm-list-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,13 @@ void alarm_list_window_snooze_menu_update(AlarmListWindow* list_window)

const gchar* name;
GtkMenuItem* item;
GList* l = NULL;

g_debug("AlarmListWindow: menu_update to %d", applet->snooze_mins);

block_list(gtk_container_get_children(GTK_CONTAINER(menu)), alarm_list_window_snooze_menu_activated);
GList* list = gtk_container_get_children(GTK_CONTAINER(menu));
block_list(list, alarm_list_window_snooze_menu_activated);

for(l = gtk_container_get_children(GTK_CONTAINER(menu)); l != NULL; l = l->next) {
for(GList* l = list; l != NULL; l = l->next) {
item = GTK_MENU_ITEM(l->data);
name = gtk_buildable_get_name(GTK_BUILDABLE(item));
if(g_strcmp0(name, target_name) == 0) {
Expand All @@ -634,7 +634,8 @@ void alarm_list_window_snooze_menu_update(AlarmListWindow* list_window)
}
}

unblock_list(gtk_container_get_children(GTK_CONTAINER(menu)), alarm_list_window_snooze_menu_activated);
unblock_list(list, alarm_list_window_snooze_menu_activated);
g_list_free(list);

g_free(target_name);
}
Expand Down
18 changes: 12 additions & 6 deletions src/alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ static void alarm_set_property(GObject* object, guint prop_id, const GValue* val
g_value_init(&strval, G_TYPE_STRING);
g_value_transform(value, &strval);
g_debug("Alarm(%p) #%d: set %s=%s", alarm, alarm->id, pspec->name, g_value_get_string(&strval));
g_value_unset(&strval);

alarm->changed = TRUE; // Do this for all properties for now (not too much overhead, anyway)

Expand All @@ -302,7 +303,9 @@ static void alarm_set_property(GObject* object, guint prop_id, const GValue* val
}
alarm->id = d;

priv->settings = g_settings_new_with_path("io.github.alarm-clock-applet.alarm", alarm_gsettings_get_dir(alarm));
gchar* gsettings_dir = alarm_gsettings_get_dir(alarm);
priv->settings = g_settings_new_with_path("io.github.alarm-clock-applet.alarm", gsettings_dir);
g_free(gsettings_dir);

alarm_gsettings_connect(alarm);
}
Expand Down Expand Up @@ -351,28 +354,28 @@ static void alarm_set_property(GObject* object, guint prop_id, const GValue* val
}
break;
case PROP_MESSAGE:
if(alarm->message)
g_free(alarm->message);

g_free(alarm->message);
alarm->message = g_strdup(g_value_get_string(value));
break;
case PROP_REPEAT:
alarm->repeat = g_value_get_flags(value);

if(alarm->active) {
if(alarm->active)
alarm_update_timestamp(alarm);
}

break;
case PROP_NOTIFY_TYPE:
alarm->notify_type = g_value_get_enum(value);
break;
case PROP_SOUND_FILE:
g_free(alarm->sound_file);
alarm->sound_file = g_strdup(g_value_get_string(value));
break;
case PROP_SOUND_LOOP:
alarm->sound_loop = g_value_get_boolean(value);
break;
case PROP_COMMAND:
g_free(alarm->command);
alarm->command = g_strdup(g_value_get_string(value));
break;
default:
Expand Down Expand Up @@ -699,6 +702,9 @@ static void alarm_dispose(GObject* object)
g_object_unref(priv->settings);
alarm_timer_remove(alarm);
alarm_clear(alarm);
g_free(alarm->command);
g_free(alarm->sound_file);
g_free(alarm->message);
}

// Called every time an alarm is created or deleted
Expand Down
3 changes: 3 additions & 0 deletions src/list-entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ GList* alarm_list_entry_list_new(const gchar* dir_uri, const gchar* supported_ty
flist = g_list_append(flist, entry);
}
}
g_object_unref(info);
}

g_file_enumerator_close(result, NULL, NULL);
g_object_unref(result);
g_object_unref(dir);

return flist;
}
Expand Down
10 changes: 8 additions & 2 deletions src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GtkBuilder* alarm_applet_ui_load(const char* name, AlarmApplet* applet)
{
GtkBuilder* builder = NULL;
GError* error = NULL;
char* filename;
gchar* filename;

filename = alarm_applet_get_data_path(name);

Expand Down Expand Up @@ -228,7 +228,13 @@ void alarm_applet_ui_init(AlarmApplet* applet)

/* Load CSS */
GtkCssProvider* css = gtk_css_provider_new();
gtk_css_provider_load_from_path(css, alarm_applet_get_data_path("alarm-clock.css"), NULL);
gchar* css_filename = alarm_applet_get_data_path("alarm-clock.css");

gtk_css_provider_load_from_path(css, css_filename, NULL);

g_free(css_filename);
css_filename = NULL;

gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_USER);

/* Connect signals */
Expand Down
10 changes: 4 additions & 6 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ gboolean is_executable_valid(gchar* executable)
/*
* Get full path to a data file
*/
char* alarm_applet_get_data_path(const char* name)
gchar* alarm_applet_get_data_path(const char* name)
{
char* filename;
gchar* filename;

/* Try the file in the source tree first */
filename = g_build_filename("..", "data", name, NULL);
Expand Down Expand Up @@ -166,9 +166,8 @@ guint unblock_signal_handlers_by_name(gpointer instance, const gchar* signal_nam
guint block_list(GList* instances, gpointer func)
{
guint blocked = 0;
GList* l = NULL;

for(l = instances; l != NULL; l = l->next) {
for(GList* l = instances; l != NULL; l = l->next) {
blocked += BLOCK(l->data, func);
}

Expand All @@ -178,9 +177,8 @@ guint block_list(GList* instances, gpointer func)
guint unblock_list(GList* instances, gpointer func)
{
guint unblocked = 0;
GList* l = NULL;

for(l = instances; l != NULL; l = l->next) {
for(GList* l = instances; l != NULL; l = l->next) {
unblocked += UNBLOCK(l->data, func);
}

Expand Down
2 changes: 1 addition & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gboolean command_run(const gchar* command);
gboolean is_executable_valid(gchar* executable);

/* Get full path of a data file */
char* alarm_applet_get_data_path(const char* name);
gchar* alarm_applet_get_data_path(const char* name);

guint block_signal_handlers_by_name(gpointer instance, const gchar* signal_name);

Expand Down

0 comments on commit 0a3a923

Please sign in to comment.