]> sigrok.org Git - libsigrok.git/commitdiff
demo: Fix memory leak
authorMarc Schink <redacted>
Wed, 30 Oct 2019 09:11:34 +0000 (10:11 +0100)
committerUwe Hermann <redacted>
Sat, 2 Nov 2019 14:32:22 +0000 (15:32 +0100)
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 <redacted>
src/hardware/demo/api.c
src/hardware/demo/protocol.c
src/hardware/demo/protocol.h

index fcd40157ea5a2ecd5aa57e547fa2175cf203fc63..3b77d40cdd36bf3f127c6bd90ef132f56204b050 100644 (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))
index 305ff17cd85d26430d926459133a063b3f32bfd8..a969d02995cb661c35ff54bf2891fbc018a1f28d 100644 (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);
index 4156f5ee539847d6c3113195061b89cd081f1e2c..230d8f3528f6fe93bed4adbb6af2ccc0a09c26d9 100644 (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