kopia lustrzana https://gitlab.com/Zwarf/picplanner
calc-milky-way: 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
rodzic
11b4f96592
commit
48fb647e99
|
@ -46,7 +46,7 @@ double
|
|||
double latitude)
|
||||
{
|
||||
double siderial_time;
|
||||
double *coordinates_milky_way;
|
||||
g_autofree double *coordinates_milky_way = NULL;
|
||||
double *coordinates_horizontal_milky_way;
|
||||
|
||||
coordinates_milky_way = picplanner_get_coordinates_rotational_milky_way ();
|
||||
|
@ -55,8 +55,6 @@ double
|
|||
latitude,
|
||||
siderial_time);
|
||||
|
||||
g_free (coordinates_milky_way);
|
||||
|
||||
return coordinates_horizontal_milky_way;
|
||||
}
|
||||
|
||||
|
@ -70,22 +68,19 @@ double
|
|||
double longitude,
|
||||
double latitude)
|
||||
{
|
||||
GDateTime *iteration_time;
|
||||
double *coordinates_milky_way;
|
||||
double *array_coordinates_milky_way = 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);
|
||||
g_autoptr (GDateTime) iteration_time =
|
||||
g_date_time_add_minutes (date_time, i*24*60/NUM_DATA_POINTS-12*60);
|
||||
g_autofree double *coordinates_milky_way =
|
||||
picplanner_get_coordinates_milky_way (iteration_time,
|
||||
longitude,
|
||||
latitude);
|
||||
|
||||
coordinates_milky_way = picplanner_get_coordinates_milky_way (iteration_time,
|
||||
longitude,
|
||||
latitude);
|
||||
array_coordinates_milky_way[2*i] = coordinates_milky_way[0];
|
||||
array_coordinates_milky_way[2*i+1] = coordinates_milky_way[1];
|
||||
|
||||
g_free (coordinates_milky_way);
|
||||
g_date_time_unref (iteration_time);
|
||||
}
|
||||
|
||||
return array_coordinates_milky_way;
|
||||
|
@ -166,4 +161,4 @@ char
|
|||
g_date_time_unref (date_time_disturbance);
|
||||
|
||||
return char_no_disturbance;
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue