Skip to content

Commit

Permalink
Fix few more leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mschoema committed Jul 20, 2024
1 parent 3bc9aa1 commit 6bb61d6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
8 changes: 7 additions & 1 deletion meos/examples/07_berlinmod_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int main(void)
stbox_in("SRID=3857;STBOX X((473212.810151,6578740.528027),(499152.544688,6607165.513683))");
GSERIALIZED *sorigin = pgis_geometry_in("Point(0 0)", -1);
STBox *trip_tiles = stbox_tile_list(trip_extent, 5e3, 5e3, 0, NULL, sorigin,
0, &no_trip_tiles);
0, true, &no_trip_tiles);
/* Compute the (value and time) tiles for speed of trips */
TBox *speed_extent = tbox_in("TBox XT([0, 35),[2020-06-01, 2020-06-05))");
Interval *duration = pg_interval_in("1 day", -1);
Expand All @@ -113,6 +113,11 @@ int main(void)
speed_record *speed_splits = malloc(sizeof(speed_record) * no_speed_tiles);
memset(speed_splits, 0, sizeof(speed_record) * no_speed_tiles);

free(trip_extent);
free(sorigin);
free(speed_extent);
free(duration);

/* Substitute the full file path in the first argument of fopen */
FILE *file = fopen("data/berlinmod_trips.csv", "r");

Expand Down Expand Up @@ -224,6 +229,7 @@ int main(void)
i, stbox_str, trip_splits[k].count, interval_str,
trip_splits[k].distance);
free(stbox_str);
free(interval_str);
}
k++;
}
Expand Down
28 changes: 24 additions & 4 deletions meos/examples/09_berlinmod_aggregate.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <string.h>
#include <time.h>
#include <meos.h>
#include <meos_internal.h>

typedef struct
{
Expand Down Expand Up @@ -134,31 +135,50 @@ int main(void)
}

/* Add the current value to the running aggregates */
extent = tpoint_extent_transfn(extent, trip_rec.trip);
STBox *new_extent = tpoint_extent_transfn(extent, trip_rec.trip);
if (extent != NULL)
free(extent);
extent = new_extent;
/* Get the time of the trip at an hour granularity */
SpanSet *ps = tstzspanset_tprecision(temporal_time(trip_rec.trip), interval, origin);
SpanSet *temptime = temporal_time(trip_rec.trip);
SpanSet *ps = tstzspanset_tprecision(temptime, interval, origin);
/* Aggregate the time of the trip */
state = tstzspanset_tcount_transfn(state, ps);
/* Free memory */
free(trip_rec.trip);
free(temptime);
free(ps);

} while (!feof(file));

printf("\n%d trip records read\n\n", no_records);

char *out_str;

printf("Extent\n");
printf("------\n\n");
printf("\%s\n\n", stbox_out(extent, 6));
out_str = stbox_out(extent, 6);
printf("\%s\n\n", out_str);
free(out_str);

printf("Temporal count\n");
printf("--------------\n\n");
int seqcount;
Temporal *tcount = temporal_tagg_finalfn(state);
Temporal **tcount_seqs = (Temporal **) temporal_sequences(tcount, &seqcount);
for (i = 0; i < seqcount; i++)
printf("\%s\n", tint_out(tcount_seqs[i]));
{
out_str = tint_out(tcount_seqs[i]);
printf("\%s\n", out_str);
free(out_str);
}

/* Free memory */
free(extent);
free(interval);
free(tcount);
for (int i = 0; i < seqcount; i++)
free(tcount_seqs[i]);
free(tcount_seqs);

/* Close the input file */
Expand Down
2 changes: 2 additions & 0 deletions meos/src/general/temporal_aggfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ tsequence_tagg_iter(const TSequence *seq1, const TSequence *seq2,
&count);
for (int i = 0; i < count; i++)
result[i] = normseqs[i];
for (int i = 0; i < nseqs; i++)
pfree(sequences[i]);
pfree(normseqs);
return count;
}
Expand Down
1 change: 1 addition & 0 deletions meos/src/general/temporal_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ tbox_tile_list(const TBox *box, Datum vsize, const Interval *duration,
tbox_tile_state_next(state);
}
*count = count1;
pfree(state);
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 @@ -3953,7 +3953,7 @@ tpointseq_speed(const TSequence *seq)
/* The resulting sequence has step interpolation */
TSequence *result = tsequence_make((const TInstant **) instants, seq->count,
seq->period.lower_inc, seq->period.upper_inc, STEP, NORMALIZE);
pfree_array((void **) instants, seq->count - 1);
pfree_array((void **) instants, seq->count);
return result;
}

Expand Down
9 changes: 6 additions & 3 deletions meos/src/point/tpoint_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ stbox_tile_list(const STBox *bounds, double xsize, double ysize, double zsize,
zsize, tunits, pt, torigin, border_inc);
bool hasz = MEOS_FLAGS_GET_Z(state->box.flags);
bool hast = MEOS_FLAGS_GET_T(state->box.flags);
int *cellcount = palloc0(sizeof(int) * MAXDIMS);
int cellcount[MAXDIMS];
cellcount[0] = ceil((state->box.xmax - state->box.xmin) / state->xsize) + 1;
cellcount[1] = ceil((state->box.ymax - state->box.ymin) / state->ysize) + 1;
int count1 = cellcount[0] * cellcount[1];
Expand All @@ -670,8 +670,9 @@ stbox_tile_list(const STBox *bounds, double xsize, double ysize, double zsize,
}
if (hast)
{
cellcount[3] = ceil((DatumGetTimestampTz(state->box.period.upper) -
DatumGetTimestampTz(state->box.period.lower)) / state->tunits) + 1;
TimestampTz duration = (DatumGetTimestampTz(state->box.period.upper) -
DatumGetTimestampTz(state->box.period.lower));
cellcount[3] = ceil((double) duration / state->tunits) + 1;
count1 *= cellcount[3];
}
STBox *result = palloc0(sizeof(STBox) * count1);
Expand All @@ -684,6 +685,8 @@ stbox_tile_list(const STBox *bounds, double xsize, double ysize, double zsize,
stbox_tile_state_next(state);
}
*count = count1;
if (state->bm) pfree(state->bm);
pfree(state);
return result;
}
#endif /* MEOS */
Expand Down

0 comments on commit 6bb61d6

Please sign in to comment.