Skip to content

Commit

Permalink
More memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mschoema committed Jul 20, 2024
1 parent 123ba22 commit 590fe6f
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 12 deletions.
1 change: 1 addition & 0 deletions meos/examples/ais_expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ int main(void)
char *t_out = pg_timestamp_out(rec.T);
sprintf(inst_buffer, "SRID=4326;Point(%lf %lf)@%s", rec.Longitude,
rec.Latitude, t_out);
free(t_out);
// TInstant *inst1 = (TInstant *) tgeogpoint_in(inst_buffer);
// if (! trips[ship].trip)
// trips[ship].trip = (Temporal *) tsequence_make_exp(
Expand Down
4 changes: 4 additions & 0 deletions meos/examples/ais_generalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ int main(void)
temp = temporal_simplify_dp(trips[i].trip, 10, true);
dp_sed_10 += temporal_mem_size(temp);
no_dp_sed_10 += temporal_num_instants(temp);
free(temp);

/* Douglas-Peucker maximum distance simplification */
temp = temporal_simplify_max_dist(trips[i].trip, 1, false);
Expand All @@ -197,6 +198,7 @@ int main(void)
temp = temporal_simplify_max_dist(trips[i].trip, 10, true);
max_dist_sed_10 += temporal_mem_size(temp);
no_max_dist_sed_10 += temporal_num_instants(temp);
free(temp);

/* Minimum distance simplification */
temp = temporal_simplify_min_dist(trips[i].trip, 1);
Expand Down Expand Up @@ -230,6 +232,8 @@ int main(void)
tprec_10s += temporal_mem_size(temp);
no_tprec_10s += temporal_num_instants(temp);
free(temp);
free(secs1);
free(secs10);
}

printf("\n---------------------------------------------------------------------------------\n");
Expand Down
3 changes: 3 additions & 0 deletions meos/examples/ais_transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ int main(void)
printf("--------------------------------\n%s\n", str_out);
free(str_out);

free(trip);
free(trip_out);

/* Clean up */
meos_finalize();
return 0;
Expand Down
6 changes: 5 additions & 1 deletion meos/examples/floatspanset_agg.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ int main(void)
/* Transform the string representing the span set into a span set value */
rec.ss = floatspanset_in(spanset_buffer);

state[rec.k%NUMBER_GROUPS] = spanset_union_transfn(state[rec.k%NUMBER_GROUPS], rec.ss);
SpanSet *ss = state[rec.k%NUMBER_GROUPS];
state[rec.k%NUMBER_GROUPS] = spanset_union_transfn(ss, rec.ss);
/* Free previous state if we allocated a new one */
if (ss && state[rec.k%NUMBER_GROUPS] != ss)
free(ss);

/* Output the float spanset value read */
char *spanset_out = floatspanset_out(rec.ss, 3);
Expand Down
5 changes: 4 additions & 1 deletion meos/examples/intspan_agg.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ int main(void)
/* Transform the string representing the span into a span value */
rec.span = intspan_in(span_buffer);

state = span_union_transfn(state, rec.span);
SpanSet *ss = state;
state = span_union_transfn(ss, rec.span);
if (ss && state != ss)
free(ss);

/* Output the input span */
char *span_out = intspan_out(rec.span);
Expand Down
3 changes: 2 additions & 1 deletion meos/examples/set_agg.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ int main()
printf("Result of the set union aggregation: %s\n", result_out);

/* Clean up allocated objects */
free(agg); free(result); free(result_out);
free(agg); free(result);
free(agg_out); free(result_out);

/* Finalize MEOS */
meos_finalize();
Expand Down
2 changes: 2 additions & 0 deletions meos/examples/spanset_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ int main()
printf("Float span set converted to integer span: %s\n", fss_conv_out);

/* Clean up allocated objects */
free(iss); free(fss);
free(iss_conv); free(fss_conv);
free(iss_out); free(fss_out);
free(iss_conv_out); free(fss_conv_out);

Expand Down
10 changes: 9 additions & 1 deletion meos/examples/stbox_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(void)
int count;
if (spacesplit)
boxes = stbox_tile_list(box, 5.0, 5.0, 5.0, timesplit ? interv : NULL,
sorigin, torigin, &count);
sorigin, torigin, true, &count);
else
spans = tstzspan_bucket_list(&box->period, interv, torigin, &count);

Expand Down Expand Up @@ -102,6 +102,14 @@ int main(void)
/* Print information about the result */
printf("\nNumber of tiles: %d\n", count);

/* Clean up allocated objects */
free(box); free(interv);
free(sorigin);
if (spacesplit)
free(boxes);
else
free(spans);

/* Finalize MEOS */
meos_finalize();

Expand Down
7 changes: 7 additions & 0 deletions meos/examples/tbox_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ int main(void)
/* Print information about the result */
printf("\nNumber of tiles: %d\n", count);

/* Clean up allocated objects */
free(box); free(interv);
if (valuesplit)
free(boxes);
else
free(spans);

/* Finalize MEOS */
meos_finalize();

Expand Down
1 change: 1 addition & 0 deletions meos/examples/tfloat_assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ int main(void)
temporal_num_instants(seq), tnumber_twavg(seq));

/* Free memory */
free(oneday);
free(seq);

/* Finalize MEOS */
Expand Down
2 changes: 1 addition & 1 deletion meos/examples/tpoint_assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int main(void)
temporal_num_instants(seq), tpoint_length(seq));

/* Free memory */
free(seq);
free(seq); free(oneday);
for (i = 0; i < MAX_INSTANTS; i++)
free(instants[i]);

Expand Down
2 changes: 1 addition & 1 deletion meos/src/general/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,6 @@ set_make_exp(const Datum *values, int count, int maxcount, meosType basetype,
return result;
}

#if MEOS
/**
* @ingroup meos_internal_setspan_constructor
* @brief Return a set from an array of values
Expand All @@ -826,6 +825,7 @@ set_make(const Datum *values, int count, meosType basetype, bool order)
return set_make_exp(values, count, count, basetype, order);
}

#if MEOS
/**
* @ingroup meos_setspan_constructor
* @brief Return an integer set from an array of values
Expand Down
3 changes: 2 additions & 1 deletion meos/src/general/temporal_analytics.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ tsequence_tprecision(const TSequence *seq, const Interval *duration,
timestamptz_cmp_internal(ininsts[k - 1]->t, upper) < 0)
{
tsequence_value_at_timestamptz(seq, upper, false, &value);
ininsts[k++] = end = tinstant_make(value, seq->temptype, upper);
ininsts[k++] = end = tinstant_make_free(value, seq->temptype, upper);
}
seq1 = tsequence_make((const TInstant **) ininsts, k, true, true, interp,
NORMALIZE);
Expand Down Expand Up @@ -298,6 +298,7 @@ tsequence_tprecision(const TSequence *seq, const Interval *duration,
value = twavg ? Float8GetDatum(tnumberseq_twavg(seq1)) :
PointerGetDatum(tpointseq_twcentroid(seq1));
outinsts[l++] = tinstant_make(value, temptype_out, lower);
pfree(seq1);
if (! twavg)
pfree(DatumGetPointer(value));
}
Expand Down
9 changes: 9 additions & 0 deletions meos/src/general/temporal_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ span_bucket_list(const Span *s, Datum size, Datum origin, int count)
span_bucket_set(state->value, state->size, state->basetype, &buckets[i]);
span_bucket_state_next(state);
}
free(state);
return buckets;
}

Expand Down Expand Up @@ -1761,8 +1762,12 @@ tnumber_value_time_split(Temporal *temp, Datum size, Interval *duration,
*count = nfrags;
if (value_buckets)
*value_buckets = v_buckets;
else
pfree(v_buckets);
if (time_buckets)
*time_buckets = t_buckets;
else
pfree(t_buckets);
return fragments;
}

Expand Down Expand Up @@ -1869,6 +1874,8 @@ tint_value_time_split(Temporal *temp, int size, Interval *duration,
values[i] = DatumGetInt32(datum_buckets[i]);
if (value_buckets)
*value_buckets = values;
else
pfree(values);
pfree(datum_buckets);
return result;
}
Expand Down Expand Up @@ -1910,6 +1917,8 @@ tfloat_value_time_split(Temporal *temp, double size, Interval *duration,
values[i] = DatumGetFloat8(datum_buckets[i]);
if (value_buckets)
*value_buckets = values;
else
pfree(values);
pfree(datum_buckets);
return result;
}
Expand Down
8 changes: 7 additions & 1 deletion meos/src/general/type_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,14 @@ set_parse(const char **str, meosType settype)
Datum d;
if (! elem_parse(str, basetype, &d))
return NULL;
DATUM_FREE(d, basetype);
int count = 1;
while (p_comma(str))
{
count++;
if (! elem_parse(str, basetype, &d))
return NULL;
DATUM_FREE(d, basetype);
}
if (! ensure_cbrace(str, type_str) ||
! ensure_end_input(str, type_str))
Expand All @@ -530,7 +532,11 @@ set_parse(const char **str, meosType settype)
for (int i = 0; i < count; i++)
gserialized_set_srid(DatumGetGserializedP(values[i]), set_srid);
}
return set_make_free(values, count, basetype, ORDER);
Set *result = set_make(values, count, basetype, ORDER);
for (int i = 0; i < count; ++i)
DATUM_FREE(values[i], basetype);
pfree(values);
return result;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions meos/src/point/pgis_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -1915,9 +1915,8 @@ geo_as_hexewkb(const GSERIALIZED *gs, const char *endian)
}
/* Create WKB hex string */
LWGEOM *geom = lwgeom_from_gserialized(gs);
lwvarlena_t *hexwkb = lwgeom_to_hexwkb_varlena(geom, variant | WKB_EXTENDED);
char *result = strdup(VARDATA(hexwkb));
pfree(hexwkb);
char *result = lwgeom_to_hexwkb_buffer(geom, variant | WKB_EXTENDED);
lwgeom_free(geom);
return result;
}

Expand Down Expand Up @@ -2105,7 +2104,7 @@ geo_same(const GSERIALIZED *gs1, const GSERIALIZED *gs2)
LWGEOM *geom1 = lwgeom_from_gserialized(gs1);
LWGEOM *geom2 = lwgeom_from_gserialized(gs2);
char result = lwgeom_same(geom1, geom2);
pfree(geom1); pfree(geom2);
lwgeom_free(geom1); lwgeom_free(geom2);
return (result == LW_TRUE);
}

Expand Down

0 comments on commit 590fe6f

Please sign in to comment.