summaryrefslogtreecommitdiff
path: root/applets
diff options
context:
space:
mode:
authorrbuj <[email protected]>2021-01-09 14:47:06 +0100
committerraveit65 <[email protected]>2021-02-07 02:45:31 +0100
commitc63575650567d111810b6633dda08409d868d02d (patch)
tree3510954ef593952b86500c71fde64303935d68ba /applets
parent9416495926b8679b7709731584e77a740959d800 (diff)
downloadmate-panel-c63575650567d111810b6633dda08409d868d02d.tar.bz2
mate-panel-c63575650567d111810b6633dda08409d868d02d.tar.xz
Redundant NULL check before freeing a variable
Diffstat (limited to 'applets')
-rw-r--r--applets/clock/clock-location.c61
-rw-r--r--applets/clock/clock.c11
-rw-r--r--applets/clock/system-timezone.c28
-rw-r--r--applets/fish/fish.c42
4 files changed, 47 insertions, 95 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));
}
diff --git a/applets/fish/fish.c b/applets/fish/fish.c
index 2f62d066..ac6cdcb8 100644
--- a/applets/fish/fish.c
+++ b/applets/fish/fish.c
@@ -211,7 +211,8 @@ static void name_value_changed(GtkEntry* entry, FishApplet* fish)
}
static void image_value_changed(GtkFileChooser* chooser, FishApplet* fish)
-{ char *path;
+{
+ char *path;
char *image;
char *path_gsettings;
@@ -998,11 +999,12 @@ static void name_changed_notify(GSettings* settings, gchar* key, FishApplet* fis
value = g_settings_get_string (settings, key);
- if (!value [0] || (fish->name && !strcmp (fish->name, value)))
+ if (!value || *value == '\0' || (fish->name && !strcmp (fish->name, value))) {
+ g_free (value);
return;
+ }
- if (fish->name)
- g_free (fish->name);
+ g_free (fish->name);
fish->name = g_strdup (value);
update_fortune_dialog (fish);
@@ -1013,8 +1015,7 @@ static void name_changed_notify(GSettings* settings, gchar* key, FishApplet* fis
strcmp (gtk_entry_get_text (GTK_ENTRY (fish->name_entry)), fish->name))
gtk_entry_set_text (GTK_ENTRY (fish->name_entry), fish->name);
- if (value)
- g_free (value);
+ g_free (value);
}
static void image_changed_notify(GSettings* settings, gchar* key, FishApplet* fish)
@@ -1023,11 +1024,12 @@ static void image_changed_notify(GSettings* settings, gchar* key, FishApplet* fi
value = g_settings_get_string (settings, key);
- if (!value [0] || (fish->image && !strcmp (fish->image, value)))
+ if (!value || *value == '\0' || (fish->image && !strcmp (fish->image, value))) {
+ g_free (value);
return;
+ }
- if (fish->image)
- g_free (fish->image);
+ g_free (fish->image);
fish->image = g_strdup (value);
load_fish_image (fish);
@@ -1047,8 +1049,7 @@ static void image_changed_notify(GSettings* settings, gchar* key, FishApplet* fi
g_free (path_chooser);
}
- if (value)
- g_free (value);
+ g_free (value);
}
static void command_changed_notify(GSettings* settings, gchar* key, FishApplet* fish)
@@ -1057,19 +1058,19 @@ static void command_changed_notify(GSettings* settings, gchar* key, FishApplet*
value = g_settings_get_string (settings, key);
- if (fish->command && !strcmp (fish->command, value))
+ if (!value || *value == '\0' || (fish->command && !strcmp (fish->command, value))) {
+ g_free (value);
return;
+ }
- if (fish->command)
- g_free (fish->command);
+ g_free (fish->command);
fish->command = g_strdup (value);
if (fish->command_entry &&
strcmp (gtk_entry_get_text (GTK_ENTRY (fish->command_entry)), fish->command))
gtk_entry_set_text (GTK_ENTRY (fish->command_entry), fish->command);
- if (value)
- g_free (value);
+ g_free (value);
}
static void n_frames_changed_notify(GSettings* settings, gchar* key, FishApplet* fish)
@@ -1792,16 +1793,13 @@ static void fish_applet_dispose (GObject *object)
g_object_unref (fish->lockdown_settings);
fish->lockdown_settings = NULL;
- if (fish->name)
- g_free (fish->name);
+ g_free (fish->name);
fish->name = NULL;
- if (fish->image)
- g_free (fish->image);
+ g_free (fish->image);
fish->image = NULL;
- if (fish->command)
- g_free (fish->command);
+ g_free (fish->command);
fish->command = NULL;
if (fish->surface)