Skip to content

Commit

Permalink
Leaks (MobilityDB#527)
Browse files Browse the repository at this point in the history
* Finding memory leaks
  • Loading branch information
estebanzimanyi authored Jul 19, 2024
1 parent 7fea79a commit 5689b1a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion meos/examples/03_ais_assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* instants, and the distance travelled. The program also stores in a CSV file
* the assembled trips.
*
* Please read the assumptions made about the input file in the file
* Please read the assumptions made about the input file in the file
* `02_ais_read.c` in the same directory. Furthermore, the program assumes the
* input file contains less than 50K observations for at most five ships.
* Also, the program does not cope with erroneous inputs, such as two or more
Expand Down Expand Up @@ -188,6 +188,7 @@ int main(void)
char *t_out = pg_timestamp_out(rec.T);
sprintf(point_buffer, "SRID=4326;Point(%lf %lf)@%s+00", rec.Longitude,
rec.Latitude, t_out);
free(t_out);
TInstant *inst1 = (TInstant *) tgeogpoint_in(point_buffer);
trips[ship].trip_instants[trips[ship].numinstants] = inst1;
TInstant *inst2 = (TInstant *) tfloatinst_make(rec.SOG, rec.T);
Expand Down
1 change: 1 addition & 0 deletions meos/examples/04_ais_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ main(int argc, char **argv)

printf("Query 'SELECT COUNT(*) FROM public.AISInstants' returned %s\n",
PQgetvalue(res, 0, 0));
PQclear(res);

/* State that the program executed successfully */
exit_value = 0;
Expand Down
13 changes: 8 additions & 5 deletions meos/examples/05_berlinmod_disassemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int main(void)
/* Get start time */
clock_t t;
t = clock();

/* Initialize MEOS */
meos_initialize(NULL, NULL);

Expand Down Expand Up @@ -177,7 +177,7 @@ int main(void)
if (first == records_in)
/* All trips have been processed */
break;
const TInstant *min_inst = temporal_instant_n(trips[first].trip,
TInstant *min_inst = temporal_instant_n(trips[first].trip,
curr_inst[first]);
int min_trip = first;

Expand All @@ -186,21 +186,24 @@ int main(void)
{
if (curr_inst[i] < 0)
continue;
const TInstant *inst = temporal_instant_n(trips[i].trip, curr_inst[i]);
TInstant *inst = temporal_instant_n(trips[i].trip, curr_inst[i]);
if (min_inst->t > inst->t)
{
free(min_inst);
min_inst = inst;
min_trip = i;
}
else
free(inst);
}

/* Write line in the CSV file */
char *date_str = pg_date_out(trips[min_trip].day);
char *geom_str = geo_as_ewkt((GSERIALIZED *)&min_inst->value, 6);
char *geom_str = geo_as_ewkt((GSERIALIZED *) &min_inst->value, 6);
char *time_str = pg_timestamptz_out(min_inst->t);
fprintf(file,"%d,%d,%s,%d,%s,%s\n", trips[min_trip].vehid,
trips[min_trip].vehid, date_str, trips[min_trip].seq, geom_str, time_str);
free(date_str); free(geom_str); free(time_str);
free(date_str); free(geom_str); free(time_str); free(min_inst);
records_out++;

/* Advance the current instant of the trip */
Expand Down
2 changes: 1 addition & 1 deletion meos/src/general/temporal_modif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ tsequence_append_tinstant(TSequence *seq, const TInstant *inst, double maxdist,
Interval *duration = minus_timestamptz_timestamptz(inst->t, last->t);
if (pg_interval_cmp(duration, maxt) > 0)
split = true;
// CANNOT pfree(duration);
pfree(duration);
}
/* If split => result is a sequence set */
if (split)
Expand Down
4 changes: 2 additions & 2 deletions meos/src/general/tsequenceset.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ ensure_valid_tinstarr_gaps(const TInstant **instants, int count, bool merge,
instants[i - 1]->t);
if (pg_interval_cmp(duration, maxt) > 0)
split = true;
// CANNOT pfree(duration);
pfree(duration);
}
if (split)
result[k++] = i;
Expand Down Expand Up @@ -961,7 +961,7 @@ tsequenceset_max_val(const TSequenceSet *ss)
/**
* @ingroup meos_internal_temporal_accessor
* @brief Return in the last argument a copy of the n-th value of a temporal
* sequence set
* sequence set
* @param[in] ss Temporal sequence set
* @param[in] n Number
* @param[out] result Value
Expand Down
8 changes: 6 additions & 2 deletions meos/src/point/pgis_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,9 @@ geo_as_text(const GSERIALIZED *gs, int precision)
return NULL;

LWGEOM *geom = lwgeom_from_gserialized(gs);
return lwgeom_to_wkt(geom, WKT_ISO, precision, NULL);
char *result = lwgeom_to_wkt(geom, WKT_ISO, precision, NULL);
lwgeom_free(geom);
return result;
}

/**
Expand All @@ -1852,7 +1854,9 @@ geo_as_ewkt(const GSERIALIZED *gs, int precision)
return NULL;

LWGEOM *geom = lwgeom_from_gserialized(gs);
return lwgeom_to_wkt(geom, WKT_EXTENDED, precision, NULL);
char *result = lwgeom_to_wkt(geom, WKT_EXTENDED, precision, NULL);
lwgeom_free(geom);
return result;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion meos/src/point/tpoint_spatialfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ geopoint_make(double x, double y, double z, bool hasz, bool geodetic,
lwpoint_make3dz(srid, x, y, z) : lwpoint_make2d(srid, x, y);
FLAGS_SET_GEODETIC(point->flags, geodetic);
GSERIALIZED *result = geo_serialize((LWGEOM *) point);
// We CANNOT lwpoint_free(point);
lwpoint_free(point);
return result;
}

Expand Down

0 comments on commit 5689b1a

Please sign in to comment.