diff options
author | rbuj <[email protected]> | 2021-01-09 14:47:06 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2021-02-07 02:45:31 +0100 |
commit | c63575650567d111810b6633dda08409d868d02d (patch) | |
tree | 3510954ef593952b86500c71fde64303935d68ba /applets/clock | |
parent | 9416495926b8679b7709731584e77a740959d800 (diff) | |
download | mate-panel-c63575650567d111810b6633dda08409d868d02d.tar.bz2 mate-panel-c63575650567d111810b6633dda08409d868d02d.tar.xz |
Redundant NULL check before freeing a variable
Diffstat (limited to 'applets/clock')
-rw-r--r-- | applets/clock/clock-location.c | 61 | ||||
-rw-r--r-- | applets/clock/clock.c | 11 | ||||
-rw-r--r-- | applets/clock/system-timezone.c | 28 |
3 files changed, 27 insertions, 73 deletions
diff --git a/applets/clock/clock-location.c b/applets/clock/clock-location.c index 9dc25e4b..7ce1c129 100644 --- a/applets/clock/clock-location.c +++ b/applets/clock/clock-location.c @@ -210,35 +210,17 @@ clock_location_finalize (GObject *g_obj) G_CALLBACK (network_changed), CLOCK_LOCATION (g_obj)); - if (priv->name) { - g_free (priv->name); - priv->name = NULL; - } - - if (priv->city) { - g_free (priv->city); - priv->city = NULL; - } + g_free (priv->name); + g_free (priv->city); if (priv->systz) { g_object_unref (priv->systz); priv->systz = NULL; } - if (priv->timezone) { - g_free (priv->timezone); - priv->timezone = NULL; - } - - if (priv->tzname) { - g_free (priv->tzname); - priv->tzname = NULL; - } - - if (priv->weather_code) { - g_free (priv->weather_code); - priv->weather_code = NULL; - } + g_free (priv->timezone); + g_free (priv->tzname); + g_free (priv->weather_code); if (priv->weather_info) { weather_info_free (priv->weather_info); @@ -277,11 +259,7 @@ clock_location_set_name (ClockLocation *loc, const gchar *name) { ClockLocationPrivate *priv = clock_location_get_instance_private (loc); - if (priv->name) { - g_free (priv->name); - priv->name = NULL; - } - + g_free (priv->name); priv->name = g_strdup (name); } @@ -298,11 +276,7 @@ clock_location_set_city (ClockLocation *loc, const gchar *city) { ClockLocationPrivate *priv = clock_location_get_instance_private (loc); - if (priv->city) { - g_free (priv->city); - priv->city = NULL; - } - + g_free (priv->city); priv->city = g_strdup (city); } @@ -319,11 +293,7 @@ clock_location_set_timezone (ClockLocation *loc, const gchar *timezone) { ClockLocationPrivate *priv = clock_location_get_instance_private (loc); - if (priv->timezone) { - g_free (priv->timezone); - priv->timezone = NULL; - } - + g_free (priv->timezone); priv->timezone = g_strdup (timezone); } @@ -360,16 +330,11 @@ clock_location_set_tzname (ClockLocation *this, const char *tzname) { ClockLocationPrivate *priv = clock_location_get_instance_private (CLOCK_LOCATION(this)); - if (priv->tzname) { - if (strcmp (priv->tzname, tzname) == 0) { - return; - } - - g_free (priv->tzname); - priv->tzname = NULL; - } + if (priv->tzname && strcmp (priv->tzname, tzname) == 0) + return; - if (tzname) { + g_free (priv->tzname); + if (tzname && *tzname != '\0') { priv->tzname = g_strdup (tzname); } else { priv->tzname = NULL; @@ -596,7 +561,7 @@ clock_location_make_current (ClockLocation *loc, static gchar * clock_location_get_valid_weather_code (const gchar *code) { - if (!code || code[0] == '\0') + if (!code || *code == '\0') return g_strdup (WEATHER_EMPTY_CODE); else return g_strdup (code); diff --git a/applets/clock/clock.c b/applets/clock/clock.c index 15c1e0cd..f3c18d27 100644 --- a/applets/clock/clock.c +++ b/applets/clock/clock.c @@ -499,8 +499,7 @@ get_updated_timeformat (ClockData *cd) static void update_timeformat (ClockData *cd) { - if (cd->timeformat) - g_free (cd->timeformat); + g_free (cd->timeformat); cd->timeformat = get_updated_timeformat (cd); } @@ -2400,17 +2399,17 @@ show_week_changed (GSettings *settings, static void setup_gsettings (ClockData *cd) { + gint format; + gchar *custom_format; + cd->settings = mate_panel_applet_settings_new (MATE_PANEL_APPLET (cd->applet), CLOCK_SCHEMA); /* hack to allow users to set custom format in dconf-editor */ - gint format; - gchar *custom_format; format = g_settings_get_enum (cd->settings, KEY_FORMAT); custom_format = g_settings_get_string (cd->settings, KEY_CUSTOM_FORMAT); g_settings_set_enum (cd->settings, KEY_FORMAT, format); g_settings_set_string (cd->settings, KEY_CUSTOM_FORMAT, custom_format); - if (custom_format != NULL) - g_free (custom_format); + g_free (custom_format); g_signal_connect (cd->settings, "changed::" KEY_FORMAT, G_CALLBACK (format_changed), cd); g_signal_connect (cd->settings, "changed::" KEY_SHOW_SECONDS, G_CALLBACK (show_seconds_changed), cd); diff --git a/applets/clock/system-timezone.c b/applets/clock/system-timezone.c index b1755aa9..199756e0 100644 --- a/applets/clock/system-timezone.c +++ b/applets/clock/system-timezone.c @@ -234,15 +234,8 @@ system_timezone_finalize (GObject *obj) systz = SYSTEM_TIMEZONE (obj); priv = system_timezone_get_instance_private (systz); - if (priv->tz) { - g_free (priv->tz); - priv->tz = NULL; - } - - if (priv->env_tz) { - g_free (priv->env_tz); - priv->env_tz = NULL; - } + g_free (priv->tz); + g_free (priv->env_tz); for (i = 0; i < CHECK_NB; i++) { if (priv->monitors[i]) @@ -265,9 +258,10 @@ system_timezone_monitor_changed (GFileMonitor *handle, gpointer user_data) { SystemTimezonePrivate *priv; - priv = system_timezone_get_instance_private (user_data); char *new_tz; + priv = system_timezone_get_instance_private (user_data); + if (event != G_FILE_MONITOR_EVENT_CHANGED && event != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT && event != G_FILE_MONITOR_EVENT_DELETED && @@ -280,13 +274,13 @@ system_timezone_monitor_changed (GFileMonitor *handle, if (strcmp (priv->tz, new_tz) != 0) { g_free (priv->tz); - priv->tz = new_tz; + priv->tz = g_strdup (new_tz); g_signal_emit (G_OBJECT (user_data), system_timezone_signals[CHANGED], 0, priv->tz); - } else - g_free (new_tz); + } + g_free (new_tz); } @@ -413,16 +407,12 @@ system_timezone_read_key_file (const char *filename, if (value[0] == '\"') { if (value[len - 1] == '\"') { - if (retval) - g_free (retval); - + g_free (retval); retval = g_strndup (value + 1, len - 2); } } else { - if (retval) - g_free (retval); - + g_free (retval); retval = g_strdup (line + strlen (key_eq)); } |