From a9abb16fe35b2a62a7667263319ff6ef649e799e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Guelfucci?= Date: Thu, 6 Jan 2011 09:58:38 +0100 Subject: [PATCH] Fix leaks reported by cppcheck. --- panel-plugin/weather-config.c | 18 ++++++++++-------- panel-plugin/weather-data.c | 8 +++++++- panel-plugin/weather-http.c | 18 +++++++++++------- panel-plugin/weather-search.c | 23 ++++++++++++----------- 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c index ab9691b..8f3dbd5 100644 --- a/panel-plugin/weather-config.c +++ b/panel-plugin/weather-config.c @@ -1,5 +1,5 @@ /* Copyright (c) 2003-2007 Xfce Development Team - * + * * 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 @@ -214,7 +214,7 @@ apply_options (xfceweather_dialog *dialog) GTK_TOGGLE_BUTTON(dialog->chk_animate_transition)); gtk_scrollbox_set_animate(GTK_SCROLLBOX(data->scrollbox), data->animation_transitions); - + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->chk_proxy_use))) data->proxy_fromenv = FALSE; @@ -235,6 +235,8 @@ apply_options (xfceweather_dialog *dialog) { xfce_err (_("Please enter proxy settings")); gtk_widget_grab_focus (dialog->txt_proxy_host); + g_free (text); + return; } @@ -274,7 +276,7 @@ option_i (datas opt) static void auto_locate_cb(const gchar *loc_name, const gchar *loc_code, gpointer user_data) { xfceweather_dialog *dialog = (xfceweather_dialog *) user_data; - + if (loc_code && loc_name) { gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_code), loc_code); gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name), loc_name); @@ -374,10 +376,10 @@ create_config_dialog (xfceweather_data *data, gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); gtk_misc_set_alignment (GTK_MISC (dialog->txt_loc_name), 0, 0.5); - + #if GTK_CHECK_VERSION(2,12,0) gtk_label_set_ellipsize (GTK_LABEL(dialog->txt_loc_name), PANGO_ELLIPSIZE_END); -#endif +#endif if (dialog->wd->location_code != NULL) gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_code), dialog->wd->location_code); @@ -385,9 +387,9 @@ create_config_dialog (xfceweather_data *data, if (dialog->wd->location_name != NULL) gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name), dialog->wd->location_name); - else if (dialog->wd->weatherdata && + else if (dialog->wd->weatherdata && get_data (dialog->wd->weatherdata, DNAM) != NULL && - strlen (get_data (dialog->wd->weatherdata, DNAM)) > 1) + strlen (get_data (dialog->wd->weatherdata, DNAM)) > 1) gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name), get_data (dialog->wd->weatherdata, DNAM)); else @@ -541,7 +543,7 @@ create_config_dialog (xfceweather_data *data, G_CALLBACK (cb_deloption), dialog); - + dialog->chk_animate_transition = gtk_check_button_new_with_label (_("Animate transitions between labels")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c index 2f5181d..62a5fb8 100644 --- a/panel-plugin/weather-data.c +++ b/panel-plugin/weather-data.c @@ -418,6 +418,8 @@ get_data_f (xml_dayf *data, p = copy_buffer (str); + g_free (str); + DBG ("value: %s", p); return p; @@ -430,6 +432,7 @@ get_unit (units unit, datas type) { gchar *str; + gchar *p; switch (type & 0x00F0) { @@ -452,5 +455,8 @@ get_unit (units unit, str = ""; } - return copy_buffer (str); + p = copy_buffer (str); + g_free (str); + + return p; } diff --git a/panel-plugin/weather-http.c b/panel-plugin/weather-http.c index 8f46eec..25bbc9a 100644 --- a/panel-plugin/weather-http.c +++ b/panel-plugin/weather-http.c @@ -149,7 +149,7 @@ weather_http_receive_data_idle (gpointer user_data) gchar *request; fd_set fds; struct timeval select_timeout; - + struct addrinfo h, *r, *a; gchar *port = NULL; gint err; @@ -183,12 +183,12 @@ weather_http_receive_data_idle (gpointer user_data) h.ai_family = AF_UNSPEC; h.ai_socktype = SOCK_STREAM; h.ai_protocol = IPPROTO_TCP; - + if (connection->proxy_port) port = g_strdup_printf("%d", connection->proxy_port); else port = g_strdup("80"); - + err = getaddrinfo(connection->proxy_host ? connection->proxy_host : connection->hostname, port, &h, &r); @@ -214,7 +214,7 @@ weather_http_receive_data_idle (gpointer user_data) return FALSE; /* open the socket */ - + for (a = r; a != NULL; a = a->ai_next) { connection->fd = socket (a->ai_family, a->ai_socktype, a->ai_protocol); if (connection->fd < 0) { @@ -232,7 +232,7 @@ weather_http_receive_data_idle (gpointer user_data) #endif if (m == 0) break; - else + else err = errno; if (weather_http_receive_data_check (connection, timeout)) @@ -271,7 +271,7 @@ weather_http_receive_data_idle (gpointer user_data) request = g_strdup_printf ("GET %s HTTP/1.1\r\n" "Host: %s\r\n" "Connection: close\r\n" - "\r\n", + "\r\n", connection->url, connection->hostname); /* send the request */ @@ -281,7 +281,11 @@ weather_http_receive_data_idle (gpointer user_data) bytes = send (connection->fd, request + m, n - m, 0); if (weather_http_receive_data_check (connection, timeout)) - return FALSE; + { + g_free (request); + + return FALSE; + } /* check for problems */ if (G_UNLIKELY (bytes < 0)) diff --git a/panel-plugin/weather-search.c b/panel-plugin/weather-search.c index 026a85b..38bddaf 100644 --- a/panel-plugin/weather-search.c +++ b/panel-plugin/weather-search.c @@ -138,7 +138,7 @@ cb_searchdone (gboolean succeed, gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog->dialog), GTK_RESPONSE_ACCEPT, TRUE); } } - + gtk_tree_view_column_set_title(dialog->column, _("Results")); return; } @@ -165,7 +165,7 @@ search_cb (GtkWidget *widget, return; } } - + g_free(dialog->last_search); dialog->last_search = g_strdup(str); @@ -242,7 +242,7 @@ create_search_dialog (GtkWindow *parent, gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); gtk_box_pack_start (GTK_BOX (dialog_vbox), vbox, TRUE, TRUE, 0); - + xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog->dialog), _("Enter a city name or zip code")); @@ -251,7 +251,7 @@ create_search_dialog (GtkWindow *parent, dialog->search_entry = gtk_entry_new (); gtk_box_pack_start (GTK_BOX (hbox), dialog->search_entry, TRUE, TRUE, 0); - + g_signal_connect (G_OBJECT (dialog->search_entry), "activate", G_CALLBACK (search_cb), dialog); @@ -335,7 +335,7 @@ typedef struct { gint proxy_port; void (*cb)(const gchar *loc_name, const gchar *loc_code, gpointer user_data); gpointer user_data; -} +} geolocation_data; static void @@ -397,7 +397,7 @@ cb_geo_searchdone (gboolean succeed, } } } - + g_free(data); xmlFreeDoc (doc); } @@ -457,7 +457,7 @@ cb_geolocation (gboolean succeed, } } } - + if (country_code && region && !strcmp(country_code, "US")) { g_free(country); country = region; @@ -465,7 +465,7 @@ cb_geolocation (gboolean succeed, } g_free(country_code); g_free(region); - + xmlFreeDoc (doc); if (city && country) { @@ -473,14 +473,15 @@ cb_geolocation (gboolean succeed, gchar *url, *sane_str; g_free(city); g_free(country); - + if ((sane_str = sanitize_str (full_loc)) == NULL) { data->cb(NULL, NULL, data->user_data); g_free(data); + g_free(full_loc); return; } g_free(full_loc); - + url = g_strdup_printf ("/search/search?where=%s", sane_str); g_free (sane_str); @@ -499,7 +500,7 @@ void weather_search_by_ip( gpointer user_data) { geolocation_data *data; - + if (!gui_cb) return; -- 1.7.2.3