| |
@@ -0,0 +1,404 @@
|
| |
+ From 3019b71a6795932656b50837d15e01427a684bee Mon Sep 17 00:00:00 2001
|
| |
+ From: =?UTF-8?q?Johan=20Rast=C3=A9n?= <johan@oljud.se>
|
| |
+ Date: Tue, 6 Oct 2020 14:54:07 +0200
|
| |
+ Subject: [PATCH 7/9] Fix some memory potential leaks
|
| |
+
|
| |
+ ---
|
| |
+ src/main.c | 2 +
|
| |
+ src/trg-client.c | 68 +++++++++++++++++++++-------------
|
| |
+ src/trg-json-widgets.c | 6 +--
|
| |
+ src/trg-main-window.c | 9 ++---
|
| |
+ src/trg-model.c | 6 +--
|
| |
+ src/trg-torrent-model.c | 6 +--
|
| |
+ src/trg-torrent-move-dialog.c | 2 +
|
| |
+ src/trg-torrent-props-dialog.c | 17 ++++++++-
|
| |
+ src/trg-trackers-model.c | 1 +
|
| |
+ src/trg-tree-view.c | 27 ++++++++++++++
|
| |
+ 10 files changed, 100 insertions(+), 44 deletions(-)
|
| |
+
|
| |
+ diff --git a/src/main.c b/src/main.c
|
| |
+ index df9bce9..ac7ff7d 100644
|
| |
+ --- a/src/main.c
|
| |
+ +++ b/src/main.c
|
| |
+ @@ -195,6 +195,8 @@ int main(int argc, char *argv[])
|
| |
+ exitCode = trg_gtkapp_init(client, argc, argv);
|
| |
+ #endif
|
| |
+
|
| |
+ + g_object_unref(client);
|
| |
+ +
|
| |
+ trg_cleanup();
|
| |
+
|
| |
+ return exitCode;
|
| |
+ diff --git a/src/trg-client.c b/src/trg-client.c
|
| |
+ index c027fb9..3eb6d30 100644
|
| |
+ --- a/src/trg-client.c
|
| |
+ +++ b/src/trg-client.c
|
| |
+ @@ -120,6 +120,23 @@ static void trg_client_dispose(GObject * object)
|
| |
+ G_OBJECT_CLASS(trg_client_parent_class)->dispose(object);
|
| |
+ }
|
| |
+
|
| |
+ +static void trg_client_finalize(GObject * object)
|
| |
+ +{
|
| |
+ + TrgClient *tc = TRG_CLIENT(object);
|
| |
+ + TrgClientPrivate *priv = tc->priv;
|
| |
+ +
|
| |
+ + g_free(priv->session_id);
|
| |
+ + json_object_unref(priv->session);
|
| |
+ + g_free(priv->url);
|
| |
+ + g_free(priv->username);
|
| |
+ + g_free(priv->password);
|
| |
+ + g_free(priv->proxy);
|
| |
+ + g_hash_table_unref(priv->torrentTable);
|
| |
+ + g_thread_pool_free(priv->pool, TRUE, TRUE);
|
| |
+ +
|
| |
+ + G_OBJECT_CLASS(trg_client_parent_class)->finalize(object);
|
| |
+ +}
|
| |
+ +
|
| |
+ static void trg_client_class_init(TrgClientClass * klass)
|
| |
+ {
|
| |
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
| |
+ @@ -129,6 +146,7 @@ static void trg_client_class_init(TrgClientClass * klass)
|
| |
+ object_class->get_property = trg_client_get_property;
|
| |
+ object_class->set_property = trg_client_set_property;
|
| |
+ object_class->dispose = trg_client_dispose;
|
| |
+ + object_class->finalize = trg_client_finalize;
|
| |
+
|
| |
+ signals[TC_SESSION_UPDATED] = g_signal_new("session-updated",
|
| |
+ G_TYPE_FROM_CLASS
|
| |
+ @@ -160,7 +178,6 @@ TrgClient *trg_client_new(void)
|
| |
+ trg_prefs_load(prefs);
|
| |
+
|
| |
+ g_mutex_init(&priv->configMutex);
|
| |
+ - //priv->tlsKey = g_private_new(NULL);
|
| |
+ priv->seedRatioLimited = FALSE;
|
| |
+ priv->seedRatioLimit = 0.00;
|
| |
+
|
| |
+ @@ -235,14 +252,9 @@ int trg_client_populate_with_settings(TrgClient * tc)
|
| |
+
|
| |
+ trg_prefs_set_connection(prefs, trg_prefs_get_profile(prefs));
|
| |
+
|
| |
+ - g_free(priv->url);
|
| |
+ - priv->url = NULL;
|
| |
+ -
|
| |
+ - g_free(priv->username);
|
| |
+ - priv->username = NULL;
|
| |
+ -
|
| |
+ - g_free(priv->password);
|
| |
+ - priv->password = NULL;
|
| |
+ + g_clear_pointer(&priv->url, g_free);
|
| |
+ + g_clear_pointer(&priv->username, g_free);
|
| |
+ + g_clear_pointer(&priv->password, g_free);
|
| |
+
|
| |
+ port =
|
| |
+ trg_prefs_get_int(prefs, TRG_PREFS_KEY_PORT, TRG_PREFS_CONNECTION);
|
| |
+ @@ -253,6 +265,7 @@ int trg_client_populate_with_settings(TrgClient * tc)
|
| |
+
|
| |
+ if (!host || strlen(host) < 1) {
|
| |
+ g_free(host);
|
| |
+ + g_free(path);
|
| |
+ g_mutex_unlock(&priv->configMutex);
|
| |
+ return TRG_NO_HOSTNAME_SET;
|
| |
+ }
|
| |
+ @@ -279,8 +292,7 @@ int trg_client_populate_with_settings(TrgClient * tc)
|
| |
+ priv->password = trg_prefs_get_string(prefs, TRG_PREFS_KEY_PASSWORD,
|
| |
+ TRG_PREFS_CONNECTION);
|
| |
+
|
| |
+ - g_free(priv->proxy);
|
| |
+ - priv->proxy = NULL;
|
| |
+ + g_clear_pointer(&priv->proxy, g_free);
|
| |
+
|
| |
+ #ifdef HAVE_LIBPROXY
|
| |
+ if ((pf = px_proxy_factory_new())) {
|
| |
+ @@ -504,10 +516,9 @@ static trg_tls *trg_tls_new(TrgClient * tc)
|
| |
+ }
|
| |
+
|
| |
+ static trg_tls *get_tls(TrgClient *tc) {
|
| |
+ - TrgClientPrivate *priv = tc->priv;
|
| |
+ - gpointer threadLocalStorage = g_private_get(&priv->tlsKey);
|
| |
+ - trg_tls *tls;
|
| |
+ -
|
| |
+ + TrgClientPrivate *priv = tc->priv;
|
| |
+ + gpointer threadLocalStorage = g_private_get(&priv->tlsKey);
|
| |
+ + trg_tls *tls;
|
| |
+ if (!threadLocalStorage) {
|
| |
+ tls = trg_tls_new(tc);
|
| |
+ g_private_set(&priv->tlsKey, tls);
|
| |
+ @@ -617,10 +628,12 @@ trg_http_perform_inner(TrgClient * tc, trg_request * request,
|
| |
+ curl_slist_free_all(headers);
|
| |
+
|
| |
+ if (response->status == CURLE_OK) {
|
| |
+ - if (httpCode == HTTP_CONFLICT && recurse == TRUE)
|
| |
+ + if (httpCode == HTTP_CONFLICT && recurse == TRUE) {
|
| |
+ + g_free(response->raw);
|
| |
+ return trg_http_perform_inner(tc, request, response, FALSE);
|
| |
+ - else if (httpCode != HTTP_OK)
|
| |
+ + } else if (httpCode != HTTP_OK) {
|
| |
+ response->status = (-httpCode) - 100;
|
| |
+ + }
|
| |
+ }
|
| |
+
|
| |
+ return response->status;
|
| |
+ @@ -631,13 +644,18 @@ int trg_http_perform(TrgClient * tc, trg_request *request, trg_response * rsp)
|
| |
+ return trg_http_perform_inner(tc, request, rsp, TRUE);
|
| |
+ }
|
| |
+
|
| |
+ -static void trg_request_free(trg_request *req) {
|
| |
+ - g_free(req->body);
|
| |
+ - g_free(req->url);
|
| |
+ - g_free(req->cookie);
|
| |
+ +static void trg_request_free(trg_request *req)
|
| |
+ +{
|
| |
+ + if (req) {
|
| |
+ + g_free(req->body);
|
| |
+ + g_free(req->url);
|
| |
+ + g_free(req->cookie);
|
| |
+ +
|
| |
+ + if (req->node)
|
| |
+ + json_node_free(req->node);
|
| |
+
|
| |
+ - if (req->node)
|
| |
+ - json_node_free(req->node);
|
| |
+ + g_free(req);
|
| |
+ + }
|
| |
+ }
|
| |
+
|
| |
+ /* formerly dispatch.c */
|
| |
+ @@ -739,7 +757,7 @@ static void dispatch_async_threadfunc(trg_request * req, TrgClient * tc)
|
| |
+ else
|
| |
+ trg_response_free(rsp);
|
| |
+
|
| |
+ - g_free(req);
|
| |
+ + trg_request_free(req);
|
| |
+ }
|
| |
+
|
| |
+ static gboolean
|
| |
+ @@ -758,7 +776,7 @@ dispatch_async_common(TrgClient * tc,
|
| |
+ if (error) {
|
| |
+ g_error("thread creation error: %s\n", error->message);
|
| |
+ g_error_free(error);
|
| |
+ - g_free(trg_req);
|
| |
+ + trg_request_free(trg_req);
|
| |
+ return FALSE;
|
| |
+ } else {
|
| |
+ return TRUE;
|
| |
+ diff --git a/src/trg-json-widgets.c b/src/trg-json-widgets.c
|
| |
+ index 99ccc44..9d47dd9 100644
|
| |
+ --- a/src/trg-json-widgets.c
|
| |
+ +++ b/src/trg-json-widgets.c
|
| |
+ @@ -53,11 +53,7 @@ void trg_json_widget_desc_free(trg_json_widget_desc * wd)
|
| |
+
|
| |
+ void trg_json_widget_desc_list_free(GList * list)
|
| |
+ {
|
| |
+ - GList *li;
|
| |
+ - for (li = list; li; li = g_list_next(li))
|
| |
+ - trg_json_widget_desc_free((trg_json_widget_desc *) li->data);
|
| |
+ -
|
| |
+ - g_list_free(list);
|
| |
+ + g_list_free_full(list, (GDestroyNotify)trg_json_widget_desc_free);
|
| |
+ }
|
| |
+
|
| |
+ void toggle_active_arg_is_sensitive(GtkToggleButton * b, gpointer data)
|
| |
+ diff --git a/src/trg-main-window.c b/src/trg-main-window.c
|
| |
+ index 5729254..69606a6 100644
|
| |
+ --- a/src/trg-main-window.c
|
| |
+ +++ b/src/trg-main-window.c
|
| |
+ @@ -847,8 +847,7 @@ confirm_action_dialog(GtkWindow * gtk_win,
|
| |
+ firstNode->data);
|
| |
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->filteredTorrentModel),
|
| |
+ &firstIter, TORRENT_COLUMN_NAME, &name, -1);
|
| |
+ - g_list_foreach(list, (GFunc) gtk_tree_path_free, NULL);
|
| |
+ - g_list_free(list);
|
| |
+ + g_list_free_full(list, (GDestroyNotify) gtk_tree_path_free);
|
| |
+
|
| |
+ dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(win),
|
| |
+ GTK_DIALOG_DESTROY_WITH_PARENT,
|
| |
+ @@ -1603,8 +1602,7 @@ torrent_selection_changed(GtkTreeSelection * selection,
|
| |
+ }
|
| |
+ }
|
| |
+
|
| |
+ - g_list_foreach(selectionList, (GFunc) gtk_tree_path_free, NULL);
|
| |
+ - g_list_free(selectionList);
|
| |
+ + g_list_free_full(selectionList, (GDestroyNotify) gtk_tree_path_free);
|
| |
+
|
| |
+ update_selected_torrent_notebook(win, TORRENT_GET_MODE_FIRST, id);
|
| |
+
|
| |
+ @@ -2202,8 +2200,7 @@ static void exec_cmd_cb(GtkWidget * w, TrgMainWindow * win)
|
| |
+ g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL,
|
| |
+ &cmd_error);
|
| |
+
|
| |
+ - g_list_foreach(selectedRows, (GFunc) gtk_tree_path_free, NULL);
|
| |
+ - g_list_free(selectedRows);
|
| |
+ + g_list_free_full(selectedRows, (GDestroyNotify) gtk_tree_path_free);
|
| |
+
|
| |
+ if (argv)
|
| |
+ g_strfreev(argv);
|
| |
+ diff --git a/src/trg-model.c b/src/trg-model.c
|
| |
+ index c9ce968..4ba2333 100644
|
| |
+ --- a/src/trg-model.c
|
| |
+ +++ b/src/trg-model.c
|
| |
+ @@ -82,7 +82,7 @@ trg_model_remove_removed(GtkListStore * model, gint serial_column,
|
| |
+ struct find_existing_item_foreach_args {
|
| |
+ gint64 id;
|
| |
+ gint search_column;
|
| |
+ - GtkTreeIter *iter;
|
| |
+ + GtkTreeIter iter;
|
| |
+ gboolean found;
|
| |
+ };
|
| |
+
|
| |
+ @@ -97,7 +97,7 @@ find_existing_item_foreachfunc(GtkTreeModel * model,
|
| |
+
|
| |
+ gtk_tree_model_get(model, iter, args->search_column, ¤tId, -1);
|
| |
+ if (currentId == args->id) {
|
| |
+ - args->iter = iter;
|
| |
+ + args->iter = *iter;
|
| |
+ return args->found = TRUE;
|
| |
+ }
|
| |
+
|
| |
+ @@ -114,6 +114,6 @@ find_existing_model_item(GtkTreeModel * model, gint search_column,
|
| |
+ args.search_column = search_column;
|
| |
+ gtk_tree_model_foreach(model, find_existing_item_foreachfunc, &args);
|
| |
+ if (args.found == TRUE)
|
| |
+ - *iter = *(args.iter);
|
| |
+ + *iter = args.iter;
|
| |
+ return args.found;
|
| |
+ }
|
| |
+ diff --git a/src/trg-torrent-model.c b/src/trg-torrent-model.c
|
| |
+ index 8e916f4..87d8b82 100644
|
| |
+ --- a/src/trg-torrent-model.c
|
| |
+ +++ b/src/trg-torrent-model.c
|
| |
+ @@ -644,11 +644,9 @@ update_torrent_iter(TrgTorrentModel * model,
|
| |
+
|
| |
+ trg_torrent_model_count_peers(model, iter, t);
|
| |
+
|
| |
+ - if (firstTrackerHost)
|
| |
+ - g_free(firstTrackerHost);
|
| |
+ + g_free(firstTrackerHost);
|
| |
+
|
| |
+ - if (peerSources)
|
| |
+ - g_free(peerSources);
|
| |
+ + g_free(peerSources);
|
| |
+
|
| |
+ g_free(lastDownloadDir);
|
| |
+ g_free(statusString);
|
| |
+ diff --git a/src/trg-torrent-move-dialog.c b/src/trg-torrent-move-dialog.c
|
| |
+ index fec1932..6f221bd 100644
|
| |
+ --- a/src/trg-torrent-move-dialog.c
|
| |
+ +++ b/src/trg-torrent-move-dialog.c
|
| |
+ @@ -176,6 +176,8 @@ static GObject *trg_torrent_move_dialog_constructor(GType type,
|
| |
+ "response",
|
| |
+ G_CALLBACK(trg_torrent_move_response_cb), priv->win);
|
| |
+
|
| |
+ + g_free(msg);
|
| |
+ +
|
| |
+ return object;
|
| |
+ }
|
| |
+
|
| |
+ diff --git a/src/trg-torrent-props-dialog.c b/src/trg-torrent-props-dialog.c
|
| |
+ index 5192fda..fd3bf6c 100644
|
| |
+ --- a/src/trg-torrent-props-dialog.c
|
| |
+ +++ b/src/trg-torrent-props-dialog.c
|
| |
+ @@ -174,7 +174,6 @@ static void trg_torrent_props_response_cb(GtkDialog * dialog, gint res_id,
|
| |
+ (priv->bandwidthPriorityCombo) ) - 1);
|
| |
+
|
| |
+ trg_json_widgets_save(priv->widgets, args);
|
| |
+ - trg_json_widget_desc_list_free(priv->widgets);
|
| |
+
|
| |
+ dispatch_async(priv->client, request, on_generic_interactive_action_response,
|
| |
+ priv->parent);
|
| |
+ @@ -659,6 +658,20 @@ static GObject *trg_torrent_props_dialog_constructor(GType type,
|
| |
+ return object;
|
| |
+ }
|
| |
+
|
| |
+ +static void trg_torrent_props_dialog_dispose(GObject * object)
|
| |
+ +{
|
| |
+ + G_OBJECT_CLASS(trg_torrent_props_dialog_parent_class)->dispose(object);
|
| |
+ +}
|
| |
+ +
|
| |
+ +static void trg_torrent_props_dialog_finalize(GObject * object)
|
| |
+ +{
|
| |
+ + TrgTorrentPropsDialogPrivate *priv = GET_PRIVATE(object);
|
| |
+ +
|
| |
+ + trg_json_widget_desc_list_free(priv->widgets);
|
| |
+ +
|
| |
+ + G_OBJECT_CLASS(trg_torrent_props_dialog_parent_class)->finalize(object);
|
| |
+ +}
|
| |
+ +
|
| |
+ static void trg_torrent_props_dialog_class_init(TrgTorrentPropsDialogClass
|
| |
+ * klass)
|
| |
+ {
|
| |
+ @@ -667,6 +680,8 @@ static void trg_torrent_props_dialog_class_init(TrgTorrentPropsDialogClass
|
| |
+ object_class->constructor = trg_torrent_props_dialog_constructor;
|
| |
+ object_class->set_property = trg_torrent_props_dialog_set_property;
|
| |
+ object_class->get_property = trg_torrent_props_dialog_get_property;
|
| |
+ + object_class->dispose = trg_torrent_props_dialog_dispose;
|
| |
+ + object_class->finalize = trg_torrent_props_dialog_finalize;
|
| |
+
|
| |
+ g_type_class_add_private(klass, sizeof(TrgTorrentPropsDialogPrivate));
|
| |
+
|
| |
+ diff --git a/src/trg-trackers-model.c b/src/trg-trackers-model.c
|
| |
+ index 2e7fb9b..6cb7d95 100644
|
| |
+ --- a/src/trg-trackers-model.c
|
| |
+ +++ b/src/trg-trackers-model.c
|
| |
+ @@ -151,6 +151,7 @@ trg_trackers_model_update(TrgTrackersModel * model,
|
| |
+ }
|
| |
+
|
| |
+ g_list_free(trackers);
|
| |
+ +
|
| |
+ trg_model_remove_removed(GTK_LIST_STORE(model),
|
| |
+ TRACKERCOL_UPDATESERIAL, updateSerial);
|
| |
+ }
|
| |
+ diff --git a/src/trg-tree-view.c b/src/trg-tree-view.c
|
| |
+ index bea3cbf..bb402d1 100644
|
| |
+ --- a/src/trg-tree-view.c
|
| |
+ +++ b/src/trg-tree-view.c
|
| |
+ @@ -90,6 +90,16 @@ gboolean trg_tree_view_is_column_showing(TrgTreeView * tv, gint index)
|
| |
+ return FALSE;
|
| |
+ }
|
| |
+
|
| |
+ +static void
|
| |
+ +trg_column_description_free(trg_column_description * desc)
|
| |
+ +{
|
| |
+ + if (desc) {
|
| |
+ + g_free(desc->header);
|
| |
+ + g_free(desc->id);
|
| |
+ + g_free(desc);
|
| |
+ + }
|
| |
+ +}
|
| |
+ +
|
| |
+ static void
|
| |
+ trg_tree_view_get_property(GObject * object, guint property_id,
|
| |
+ GValue * value, GParamSpec * pspec)
|
| |
+ @@ -766,6 +776,21 @@ GList *trg_tree_view_get_selected_refs_list(GtkTreeView * tv)
|
| |
+ return refList;
|
| |
+ }
|
| |
+
|
| |
+ +static void trg_tree_view_dispose(GObject * object)
|
| |
+ +{
|
| |
+ + G_OBJECT_CLASS(trg_tree_view_parent_class)->dispose(object);
|
| |
+ +}
|
| |
+ +
|
| |
+ +static void trg_tree_view_finalize(GObject * object)
|
| |
+ +{
|
| |
+ + TrgTreeViewPrivate *priv = TRG_TREE_VIEW_GET_PRIVATE(object);
|
| |
+ +
|
| |
+ + g_list_free_full(priv->columns, (GDestroyNotify) trg_column_description_free);
|
| |
+ + g_free(priv->configId);
|
| |
+ +
|
| |
+ + G_OBJECT_CLASS(trg_tree_view_parent_class)->finalize(object);
|
| |
+ +}
|
| |
+ +
|
| |
+ static void trg_tree_view_class_init(TrgTreeViewClass * klass)
|
| |
+ {
|
| |
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
| |
+ @@ -775,6 +800,8 @@ static void trg_tree_view_class_init(TrgTreeViewClass * klass)
|
| |
+ object_class->get_property = trg_tree_view_get_property;
|
| |
+ object_class->set_property = trg_tree_view_set_property;
|
| |
+ object_class->constructor = trg_tree_view_constructor;
|
| |
+ + object_class->dispose = trg_tree_view_dispose;
|
| |
+ + object_class->finalize = trg_tree_view_finalize;
|
| |
+
|
| |
+ g_object_class_install_property(object_class,
|
| |
+ PROP_PREFS,
|
| |
+ --
|
| |
+ 2.28.0
|
| |
+
|
| |
are in same order as in upstream repository.