kwo pushed a commit to branch master.

http://git.enlightenment.org/e16/e16.git/commit/?id=8994417b49bf82b9d999146268db92f127fd0a34

commit 8994417b49bf82b9d999146268db92f127fd0a34
Author: Kim Woelders <[email protected]>
Date:   Sat Mar 30 18:02:17 2019 +0100

    Fix memory leak in pulseaudio sound loader
    
    The leak only happens when a sound file is first loaded so the leakage
    will not grow indefinitely.
    
    Also eliminate global sample_stream and sample_length.
---
 src/sound_pa.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/sound_pa.c b/src/sound_pa.c
index 2cb0daa8..aad87cdd 100644
--- a/src/sound_pa.c
+++ b/src/sound_pa.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2018 Kim Woelders
+ * Copyright (C) 2008-2019 Kim Woelders
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
@@ -52,8 +52,6 @@ static pa_mainloop *pa_mloop = NULL;
 static pa_mainloop_api *mainloop_api = NULL;
 static pa_context  *pa_ctx = NULL;
 
-static pa_stream   *sample_stream = NULL;
-static size_t       sample_length = 0;
 static int          pa_block = 0;
 
 static void         _sound_pa_Exit(void);
@@ -207,6 +205,7 @@ _sound_pa_Load(const char *file)
 {
    Sample             *s;
    pa_sample_spec      sample_spec;
+   pa_stream          *sample_stream = NULL;
    int                 err;
    char               *p;
 
@@ -241,24 +240,26 @@ _sound_pa_Load(const char *file)
      }
    sample_spec.rate = s->ssd.rate;
    sample_spec.channels = s->ssd.channels;
-   sample_length = s->ssd.size;
 
    sample_stream = pa_stream_new(pa_ctx, s->name, &sample_spec, NULL);
    if (!sample_stream)
       goto bail_out;
    pa_stream_set_state_callback(sample_stream, stream_state_callback, NULL);
    pa_stream_set_write_callback(sample_stream, stream_write_callback, s);
-   pa_stream_connect_upload(sample_stream, sample_length);
+   pa_stream_connect_upload(sample_stream, s->ssd.size);
 
    err = dispatch(-1);
    if (err)
       goto bail_out;
 
    EFREE_NULL(s->ssd.data);
+   pa_stream_unref(sample_stream);
 
    return s;
 
  bail_out:
+   if (sample_stream)
+      pa_stream_unref(sample_stream);
    _sound_pa_Destroy(s);
    return NULL;
 }

-- 


Reply via email to