demo: Fix memory leak

How to reproduce:

 $ G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind --leak-check=full sigrok-cli --scan --driver demo

Signed-off-by: Marc Schink <dev@zapb.de>
This commit is contained in:
Marc Schink 2019-10-30 10:11:34 +01:00 committed by Uwe Hermann
parent 76dea519e4
commit f216309fd0
3 changed files with 12 additions and 0 deletions

View File

@ -225,6 +225,8 @@ static void clear_helper(struct dev_context *devc)
GHashTableIter iter;
void *value;
demo_free_analog_pattern(devc);
/* Analog generators. */
g_hash_table_iter_init(&iter, devc->ch_ag);
while (g_hash_table_iter_next(&iter, NULL, &value))

View File

@ -252,6 +252,15 @@ SR_PRIV void demo_generate_analog_pattern(struct dev_context *devc)
devc->analog_patterns[PATTERN_ANALOG_RANDOM] = pattern;
}
SR_PRIV void demo_free_analog_pattern(struct dev_context *devc)
{
g_free(devc->analog_patterns[PATTERN_SQUARE]);
g_free(devc->analog_patterns[PATTERN_SINE]);
g_free(devc->analog_patterns[PATTERN_TRIANGLE]);
g_free(devc->analog_patterns[PATTERN_SAWTOOTH]);
g_free(devc->analog_patterns[PATTERN_ANALOG_RANDOM]);
}
static uint64_t encode_number_to_gray(uint64_t nr)
{
return nr ^ (nr >> 1);

View File

@ -161,6 +161,7 @@ struct analog_gen {
};
SR_PRIV void demo_generate_analog_pattern(struct dev_context *devc);
SR_PRIV void demo_free_analog_pattern(struct dev_context *devc);
SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data);
#endif