Skip to content

Commit

Permalink
Fix memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mschoema committed Jul 19, 2024
1 parent 5689b1a commit d1b6d1a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
5 changes: 4 additions & 1 deletion meos/src/general/type_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,12 @@ temporal_as_mfjson(const Temporal *temp, bool with_bbox, int flags,
if (flags == 0)
return result;

/* Convert to JSON and back to a C string to apply flags using json-c */
struct json_object *jobj = json_tokener_parse(result);
pfree(result);
return (char *) json_object_to_json_string_ext(jobj, flags);
result = strdup(json_object_to_json_string_ext(jobj, flags));
json_object_put(jobj);
return result;
}

/*****************************************************************************
Expand Down
23 changes: 13 additions & 10 deletions meos/src/general/type_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,8 @@ span_parse(const char **str, meosType spantype, bool end, Span *span)
if (end && ! ensure_end_input(str, "span"))
return false;

if (! span)
return true;
span_set(lower, upper, lower_inc, upper_inc, basetype, spantype, span);
if (span)
span_set(lower, upper, lower_inc, upper_inc, basetype, spantype, span);
return true;
}

Expand Down Expand Up @@ -663,13 +662,16 @@ tinstant_parse(const char **str, meosType temptype, bool end,
if (! temporal_basetype_parse(str, basetype, &elem))
return false;
TimestampTz t = timestamp_parse(str);
if (t == DT_NOEND)
return false;
/* Ensure there is no more input */
if (end && ! ensure_end_input(str, "temporal"))
if (t == DT_NOEND ||
/* Ensure there is no more input */
(end && ! ensure_end_input(str, "temporal")))
{
DATUM_FREE(elem, basetype);
return false;
}
if (result)
*result = tinstant_make_free(elem, temptype, t);
*result = tinstant_make(elem, temptype, t);
DATUM_FREE(elem, basetype);
return true;
}

Expand Down Expand Up @@ -774,8 +776,9 @@ tcontseq_parse(const char **str, meosType temptype, interpType interp,
p_cbracket(str);
p_cparen(str);
if (result)
*result = tsequence_make_free(instants, count, lower_inc, upper_inc,
interp, NORMALIZE);
*result = tsequence_make((const TInstant **) instants, count,
lower_inc, upper_inc, interp, NORMALIZE);
pfree_array((void **) instants, count);
return true;
}

Expand Down
15 changes: 9 additions & 6 deletions meos/src/point/tpoint_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <meos.h>
#include <meos_internal.h>
#include "general/type_parser.h"
#include "general/type_util.h"
#include "point/tpoint_spatialfuncs.h"

/*****************************************************************************/
Expand Down Expand Up @@ -286,15 +287,16 @@ tpointinst_parse(const char **str, meosType temptype, bool end,
return false;
}
TimestampTz t = timestamp_parse(str);
if (t == DT_NOEND)
return false;
if (end && ! ensure_end_input(str, "temporal point"))
if (t == DT_NOEND ||
/* Ensure there is no more input */
(end && ! ensure_end_input(str, "temporal point")))
{
pfree(gs);
return false;
}
if (result)
*result = tinstant_make_free(PointerGetDatum(gs), temptype, t);
*result = tinstant_make(PointerGetDatum(gs), temptype, t);
pfree(gs);
return true;
}

Expand Down Expand Up @@ -399,8 +401,9 @@ tpointseq_cont_parse(const char **str, meosType temptype, interpType interp,
p_cbracket(str);
p_cparen(str);
if (result)
*result = tsequence_make_free(instants, count, lower_inc, upper_inc,
interp, NORMALIZE);
*result = tsequence_make((const TInstant **) instants, count,
lower_inc, upper_inc, interp, NORMALIZE);
pfree_array((void **) instants, count);
return true;
}

Expand Down

0 comments on commit d1b6d1a

Please sign in to comment.