kopia lustrzana https://gitlab.com/Zwarf/picplanner
time-picker: Prefer g_auto* macros
g_autofree will automatically free variables when they go out of scope. g_autoptr will do the same, but using the appropriate freefunc for the given type, e.g. GDateTime -> g_date_time_unref() or GObject -> g_object_unref(). This automatic cleanup reduces the risk of memory leaks and allows getting rid of some lines of code.main
rodzic
933089cf6f
commit
3255001a90
|
@ -53,10 +53,9 @@ void
|
|||
time_picker_set_time_zone (TimePicker *time_picker,
|
||||
double time_zone)
|
||||
{
|
||||
char *char_time_zone;
|
||||
g_autofree char *char_time_zone = NULL;
|
||||
char_time_zone = g_strdup_printf ("UTC %s%.1f", time_zone>=0 ? "+" : "", time_zone);
|
||||
gtk_label_set_text (GTK_LABEL (time_picker->label_time_zone), char_time_zone);
|
||||
g_free (char_time_zone);
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,7 +134,7 @@ static gboolean
|
|||
time_spin_button_text (GtkSpinButton *self)
|
||||
{
|
||||
int value;
|
||||
char *button_text;
|
||||
g_autofree char *button_text = NULL;
|
||||
GtkAdjustment *adjustment;
|
||||
|
||||
adjustment = gtk_spin_button_get_adjustment (self);
|
||||
|
@ -143,7 +142,6 @@ time_spin_button_text (GtkSpinButton *self)
|
|||
button_text = g_strdup_printf ("%02d", value);
|
||||
gtk_editable_set_text (GTK_EDITABLE (self),
|
||||
button_text);
|
||||
g_free (button_text);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -156,9 +154,9 @@ static void
|
|||
day_selected (GtkCalendar *self,
|
||||
TimePicker *time_picker)
|
||||
{
|
||||
GDateTime *date_selected;
|
||||
g_autoptr (GDateTime) date_selected = NULL;
|
||||
GtkPopover *popover;
|
||||
char *button_text;
|
||||
g_autofree char *button_text = NULL;
|
||||
|
||||
(void) self;
|
||||
date_selected = gtk_calendar_get_date (GTK_CALENDAR (time_picker->calendar));
|
||||
|
@ -181,9 +179,6 @@ day_selected (GtkCalendar *self,
|
|||
popover = GTK_POPOVER(time_picker->calendar_popover);
|
||||
gtk_popover_popdown (popover);
|
||||
|
||||
g_free (button_text);
|
||||
g_date_time_unref (date_selected);
|
||||
|
||||
input_changed (GTK_WIDGET (self), time_picker);
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue