Skip to content

Commit

Permalink
Finding memory leaks (MobilityDB#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanzimanyi authored Jul 20, 2024
1 parent 6480b28 commit 11a404a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 18 deletions.
2 changes: 2 additions & 0 deletions meos/examples/tfloat_assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ int main(void)

seq = (Temporal *) tsequence_make((const TInstant **) instants, MAX_INSTANTS,
true, true, STEP, true);
for (i = 0; i < MAX_INSTANTS; i++)
free(instants[i]);

/* Print information about the sequence */
printf("Number of generated instants: %d, Time-weighted average: %f\n",
Expand Down
12 changes: 6 additions & 6 deletions meos/examples/tfloat_expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
* outputs the number of instants and the time-weighted average.
*
* This program and the program tfloat_expand.c in the same directory can be
* used to compare the two alternative strategies for
* (1) assembling the sequence at the end from the input instants
* (2) expanding the sequence at each input instant
* used to compare the two alternative strategies for
* (1) assembling the sequence at the end from the input instants
* (2) expanding the sequence at each input instant
*
* The instants are generated so they are not redundant, that is, all input
* instants will appear in the final sequence.
* instants will appear in the final sequence.
*
* The program can be build as follows
* @code
Expand All @@ -64,7 +64,7 @@ int main(void)
clock_t tm;
tm = clock();

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

/* Expandable sequence */
Expand Down Expand Up @@ -98,7 +98,7 @@ int main(void)
temporal_num_instants(seq), tnumber_twavg(seq));

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

/* Finalize MEOS */
meos_finalize();
Expand Down
8 changes: 7 additions & 1 deletion meos/examples/tfloat_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,18 @@ int main(void)
temp_str);
printf("%s", output_buffer);
if (timesplit) free(time_str);
free(temp_str);
free(result[i]); free(temp_str);
}

/* Print information about the result */
printf("\nNumber of fragments: %d\n", count);

/* Free memory */
free(tfloat); free(interv); free(result);
if (valuesplit)
free(value_buckets);
free(time_buckets);

/* Finalize MEOS */
meos_finalize();

Expand Down
3 changes: 3 additions & 0 deletions meos/examples/tpoint_assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ int main(void)
sprintf(inst_buffer, "Point(%d %d)@%s", value, value, time_str);
instants[i] = (TInstant *) tgeompoint_in(inst_buffer);
#endif
free(time_str);
}

printf("\nAssembing the instants ...\n");

seq = (Temporal *) tsequence_make((const TInstant **) instants, MAX_INSTANTS,
true, true, LINEAR, true);

Expand Down
4 changes: 2 additions & 2 deletions meos/examples/tpoint_expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ int main(void)
EXPAND ? 2 : 1, true, true, LINEAR, false);
else
seq = temporal_append_tinstant((Temporal *) seq, inst, 0.0, NULL, EXPAND);
free(inst);
free(inst); free(time_str);
}

/* Print information about the sequence */
printf("\nNumber of instants: %d, Distance : %lf\n",
temporal_num_instants(seq), tpoint_length(seq));

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

/* Calculate the elapsed time */
time = clock() - time;
Expand Down
20 changes: 15 additions & 5 deletions meos/examples/ttext_assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

#define MAX_INSTANTS 1000000
/* Number of instants in a batch for printing a marker */
#define NO_INSTANTS_BATCH 1000
#define NO_INSTANTS_BATCH 10000
/* Maximum length in characters of the input instant */
#define MAX_LENGTH_INST 64
/* Maximum length in characters of the text values in the instants */
Expand All @@ -76,10 +76,18 @@ int main(void)
/* Seed the random number generator with the current time in seconds. */
srandom (time (0));

printf("Generating the instants (one '*' marker every %d instants)\n",
NO_INSTANTS_BATCH);

TimestampTz t = pg_timestamptz_in("1999-12-31", -1);
for (i = 0; i < MAX_INSTANTS; i++)
{
/* Generate the instant */
if (i % NO_INSTANTS_BATCH == 0)
{
printf("*");
fflush(stdout);
}
/* Use a random generator to set the length of the text value */
int len = random() % MAX_LENGTH_TEXT + 1;
char *value = malloc(sizeof(char) * (len + 2));
Expand All @@ -97,13 +105,15 @@ int main(void)
/* Print information about the sequence */
// Uncomment the next line to see the resulting sequence value
// printf("%s\n", ttext_out(seq));
char *str = text2cstring(ttext_end_value(seq));
printf("Number of instants: %d, Last value : %s\n",
text *txt = ttext_end_value(seq);
char *str = text2cstring(txt);
printf("\nNumber of instants: %d, Last value : %s\n",
temporal_num_instants(seq), str);

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

/* Calculate the elapsed time */
tm = clock() - tm;
Expand Down
11 changes: 7 additions & 4 deletions meos/examples/ttext_expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
* - False: sequences are compacted when compacting the sequence set
*/
#define COMPACT_COMP_SEQS false
/* Determine whether debug messages showing the expansion of sequences and
* and sequence sets are shown */
#define DEBUG false

/* Main program */
int main(void)
Expand Down Expand Up @@ -140,7 +143,7 @@ int main(void)
seq = (TSequence *) tsequence_append_tinstant(seq, inst, 0.0, NULL,
true);
/* Print a marker when the sequence has been expanded */
if (EXPAND_SEQ && maxcount != seq->maxcount)
if (DEBUG && EXPAND_SEQ && maxcount != seq->maxcount)
{
printf(" Seq -> %d ", seq->maxcount);
fflush(stdout);
Expand Down Expand Up @@ -190,13 +193,13 @@ int main(void)

/* Print information about the last sequence */
seq = temporal_end_sequence((Temporal *) ss1);
char *str = text2cstring(ttext_end_value((Temporal *) seq));
text *txt = ttext_end_value((Temporal *) seq);
char *str = text2cstring(txt);
printf("Number of instants in the last sequence: %d, Last value : %s\n",
seq->count, str);

/* Free memory */
free(ss1);
free(str);
free(ss1); free(onehour); free(txt); free(str);

/* Calculate the elapsed time */
tm = clock() - tm;
Expand Down

0 comments on commit 11a404a

Please sign in to comment.