From: Marc Schink Date: Wed, 30 Oct 2019 09:11:34 +0000 (+0100) Subject: demo: Fix memory leak X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f216309fd0576dfe5bad25fa91ade3db35d66a5f;p=libsigrok.git 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 --- diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index fcd40157..3b77d40c 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -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)) diff --git a/src/hardware/demo/protocol.c b/src/hardware/demo/protocol.c index 305ff17c..a969d029 100644 --- a/src/hardware/demo/protocol.c +++ b/src/hardware/demo/protocol.c @@ -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); diff --git a/src/hardware/demo/protocol.h b/src/hardware/demo/protocol.h index 4156f5ee..230d8f35 100644 --- a/src/hardware/demo/protocol.h +++ b/src/hardware/demo/protocol.h @@ -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