pidgin/pidginaccountfilterconnected.c

Thu, 02 Mar 2023 23:58:21 -0600

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Thu, 02 Mar 2023 23:58:21 -0600
changeset 42109
27c84f0b3258
parent 41864
6f490dec468f
child 42575
580339aa47cc
permissions
-rw-r--r--

Fix leaks in debug window

Fixes two leaks from the debug window:
```
22 bytes in 1 blocks are definitely lost in loss record 7,038 of 41,972
at 0x484386F: malloc (vg_replace_malloc.c:393)
by 0x4980168: g_malloc (gmem.c:130)
by 0x4995602: g_strdup (gstrfuncs.c:363)
by 0x4CFB782: purple_prefs_connect_callback (prefs.c:1301)
by 0x48AA524: pidgin_debug_init (pidgindebug.c:918)
by 0x48B8F9E: pidgin_ui_start (pidginui.c:146)
by 0x4D37B01: purple_ui_start (purpleui.c:397)
by 0x4CE3BA6: purple_core_init (core.c:211)
by 0x48A384F: pidgin_application_startup (pidginapplication.c:820)
by 0x4DD3553: UnknownInlinedFun (gclosure.c:895)
by 0x4DD3553: g_signal_emit_valist (gsignal.c:3456)
by 0x4DD3632: g_signal_emit (gsignal.c:3606)
by 0x5815B82: g_application_register (gapplication.c:2211)
```
and
```
32 bytes in 1 blocks are definitely lost in loss record 15,308 of 41,972
at 0x484386F: malloc (vg_replace_malloc.c:393)
by 0x4980168: g_malloc (gmem.c:130)
by 0x4997AB5: g_slice_alloc (gslice.c:1074)
by 0x495E14C: UnknownInlinedFun (gdatetime.c:678)
by 0x495E14C: g_date_time_from_instant (gdatetime.c:774)
by 0x495F4E9: g_date_time_new_now_local (gdatetime.c:989)
by 0x48A82F9: save_response_cb (pidgindebug.c:136)
by 0x4DB4375: g_cclosure_marshal_VOID__INTv (gmarshal.c:596)
by 0x4DD3553: UnknownInlinedFun (gclosure.c:895)
by 0x4DD3553: g_signal_emit_valist (gsignal.c:3456)
by 0x4DD3632: g_signal_emit (gsignal.c:3606)
by 0x4DB5FBF: g_closure_invoke (gclosure.c:832)
by 0x4DE3D85: signal_emit_unlocked_R.isra.0 (gsignal.c:3796)
by 0x4DD3419: g_signal_emit_valist (gsignal.c:3549)
```

Testing Done:
Ran in valgrind, saved the debug logs to a file, and the above leaks were gone.

Reviewed at https://reviews.imfreedom.org/r/2304/

/*
 * Pidgin - Internet Messenger
 * Copyright (C) Pidgin Developers <devel@pidgin.im>
 *
 * Pidgin is the legal property of its developers, whose names are too numerous
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
 */

#include "pidgin/pidginaccountfilterconnected.h"

#include <purple.h>

struct _PidginAccountFilterConnected {
	GtkFilter parent;
};

/******************************************************************************
 * Callbacks
 *****************************************************************************/
static void
pidgin_account_filter_connected_changed(PurpleConnection *connection,
                                        gpointer data)
{
	PidginAccountFilterConnected *filter = NULL;
	PurpleConnectionState state;

	filter = PIDGIN_ACCOUNT_FILTER_CONNECTED(data);

	state = purple_connection_get_state(connection);
	gtk_filter_changed(GTK_FILTER(filter),
	                   (state == PURPLE_CONNECTION_STATE_CONNECTED) ?
	                   GTK_FILTER_CHANGE_LESS_STRICT :
	                   GTK_FILTER_CHANGE_MORE_STRICT);
}

/******************************************************************************
 * GtkFilter Implementation
 *****************************************************************************/
static GtkFilterMatch
pidgin_account_filter_connected_get_strictness(G_GNUC_UNUSED GtkFilter *self) {
	return GTK_FILTER_MATCH_SOME;
}

static gboolean
pidgin_account_filter_connected_match(G_GNUC_UNUSED GtkFilter *self,
                                      gpointer item)
{
	gboolean ret = FALSE;

	if(PURPLE_IS_ACCOUNT(item)) {
		ret = purple_account_is_connected(PURPLE_ACCOUNT(item));
	}

	return ret;
}

/******************************************************************************
 * GObject Implementation
 *****************************************************************************/
G_DEFINE_TYPE(PidginAccountFilterConnected, pidgin_account_filter_connected,
              GTK_TYPE_FILTER)

static void
pidgin_account_filter_connected_init(PidginAccountFilterConnected *filter) {
	gpointer connections_handle = NULL;

	/* we connect to the connections signals to force a refresh of the filter */
	connections_handle = purple_connections_get_handle();
	purple_signal_connect(connections_handle, "signed-on", filter,
	                      G_CALLBACK(pidgin_account_filter_connected_changed),
	                      filter);
	purple_signal_connect(connections_handle, "signed-off", filter,
	                      G_CALLBACK(pidgin_account_filter_connected_changed),
	                      filter);
}

static void
pidgin_account_filter_connected_finalize(GObject *obj) {
	purple_signals_disconnect_by_handle(obj);

	G_OBJECT_CLASS(pidgin_account_filter_connected_parent_class)->finalize(obj);
}

static void
pidgin_account_filter_connected_class_init(PidginAccountFilterConnectedClass *klass) {
	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
	GtkFilterClass *filter_class = GTK_FILTER_CLASS(klass);

	obj_class->finalize = pidgin_account_filter_connected_finalize;

	filter_class->get_strictness = pidgin_account_filter_connected_get_strictness;
	filter_class->match = pidgin_account_filter_connected_match;
}

/******************************************************************************
 * API
 *****************************************************************************/
GtkFilter *
pidgin_account_filter_connected_new(void)
{
	return g_object_new(PIDGIN_TYPE_ACCOUNT_FILTER_CONNECTED, NULL);
}

mercurial