Skip to content
Snippets Groups Projects
Commit 2370da82 authored by Georges Da Costa's avatar Georges Da Costa
Browse files

Calls cleaners and free memory at exit even with SIGINT and SIGTERM

parent 0de2cd83
No related branches found
No related tags found
No related merge requests found
Pipeline #8848 passed
......@@ -159,14 +159,6 @@ void flush(int none)
}
FILE *output;
void flushexit()
{
if (output != NULL) {
fflush(output);
fclose(output);
}
}
unsigned int nb_sources = 0;
void **states = NULL;
getter_t *getter = NULL;
......@@ -176,6 +168,25 @@ unsigned int nb_sensors = 0;
char **labels = NULL;
uint64_t *values = NULL;
void flushexit()
{
if (output != NULL) {
fflush(output);
fclose(output);
}
for (unsigned int i = 0; i < nb_sources; i++) {
cleaner[i](states[i]);
}
if (nb_sources > 0) {
free(getter);
free(cleaner);
free(labels);
free(values);
free(states);
}
}
void add_source(Sensor *cpt, char *arg)
{
nb_sources++;
......@@ -227,7 +238,8 @@ int main(int argc, char **argv)
output = stdout;
atexit(flushexit);
signal(15, flush);
signal(SIGTERM, flush);
signal(SIGINT, flush);
int opt;
struct optparse options;
......@@ -369,16 +381,5 @@ int main(int argc, char **argv)
usleep(1000 * 1000 / frequency - (ts.tv_nsec / 1000) % (1000 * 1000 / frequency));
}
for (unsigned int i = 0; i < nb_sources; i++) {
cleaner[i](states[i]);
}
if (nb_sources > 0) {
free(getter);
free(cleaner);
free(labels);
free(values);
free(states);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment