calc-sun: 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.
theme-selector
Evangelos Ribeiro Tzaras 2023-07-17 20:23:20 +02:00
rodzic c86104db9f
commit a9493dc507
1 zmienionych plików z 6 dodań i 12 usunięć

Wyświetl plik

@ -64,7 +64,7 @@ double
double latitude)
{
double siderial_time;
double *coordinates_sun;
g_autofree double *coordinates_sun = NULL;
double *coordinates_horizontal_sun;
@ -73,7 +73,6 @@ double
coordinates_horizontal_sun = picplanner_transform_rotational_to_horizontal (coordinates_sun,
latitude,
siderial_time);
g_free (coordinates_sun);
return coordinates_horizontal_sun;
}
@ -84,23 +83,18 @@ double
double longitude,
double latitude)
{
GDateTime *iteration_time;
double *coordinates_sun;
double *array_coordinates_sun = malloc (sizeof (double) * 2 * NUM_DATA_POINTS);
for (int i=0; i<NUM_DATA_POINTS; i++)
{
iteration_time = g_date_time_add_minutes (date_time, i*24*60/NUM_DATA_POINTS-12*60);
coordinates_sun = picplanner_get_coordinates_sun (iteration_time,
longitude,
latitude);
GDateTime *iteration_time = g_date_time_add_minutes (date_time, i*24*60/NUM_DATA_POINTS-12*60);
g_autofree double *coordinates_sun =
picplanner_get_coordinates_sun (iteration_time,
longitude,
latitude);
array_coordinates_sun[2*i] = coordinates_sun[0];
array_coordinates_sun[2*i+1] = coordinates_sun[1];
g_free (coordinates_sun);
g_date_time_unref (iteration_time);
}
return array_coordinates_sun;