[pulseaudio-discuss] [PATCH 1/5] core: Change sematics of pa_flist_new_with_name()

oku at iki.fi oku at iki.fi
Mon Dec 20 08:47:20 PST 2010


From: Jyri Sarha <jyri.sarha at nokia.com>

Name string is copied and added to flist structure. The original is
responsibility of the caller. The name is only used for debug printing.
---
 src/pulsecore/flist.c |    5 ++++-
 src/pulsecore/flist.h |    4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/pulsecore/flist.c b/src/pulsecore/flist.c
index 1867525..54f08c2 100644
--- a/src/pulsecore/flist.c
+++ b/src/pulsecore/flist.c
@@ -83,13 +83,14 @@ static void stack_push(pa_atomic_ptr_t *list, pa_flist_elem *new_elem) {
 pa_flist *pa_flist_new_with_name(unsigned size, const char *name) {
     pa_flist *l;
     unsigned i;
+    pa_assert(name);
 
     if (!size)
         size = FLIST_SIZE;
 
     l = pa_xmalloc0(sizeof(pa_flist) + sizeof(pa_flist_elem) * size);
 
-    l->name = name;
+    l->name = pa_xstrdup(name);
     l->size = size;
     pa_atomic_ptr_store(&l->stored, NULL);
     pa_atomic_ptr_store(&l->empty, NULL);
@@ -105,6 +106,7 @@ pa_flist *pa_flist_new(unsigned size) {
 
 void pa_flist_free(pa_flist *l, pa_free_cb_t free_cb) {
     pa_assert(l);
+    pa_assert(l->name);
 
     if (free_cb) {
         pa_flist_elem *elem;
@@ -112,6 +114,7 @@ void pa_flist_free(pa_flist *l, pa_free_cb_t free_cb) {
             free_cb(pa_atomic_ptr_load(&elem->ptr));
     }
 
+    pa_xfree(l->name);
     pa_xfree(l);
 }
 
diff --git a/src/pulsecore/flist.h b/src/pulsecore/flist.h
index 7fb5035..915b113 100644
--- a/src/pulsecore/flist.h
+++ b/src/pulsecore/flist.h
@@ -33,8 +33,8 @@
 typedef struct pa_flist pa_flist;
 
 pa_flist * pa_flist_new(unsigned size);
-/* Freeing the name is responsibility of caller. The name is only used
- * for debug printing. */
+/* Name string is copied and added to flist structure. The original is
+ * responsibility of the caller. The name is only used for debug printing. */
 pa_flist * pa_flist_new_with_name(unsigned size, const char *name);
 void pa_flist_free(pa_flist *l, pa_free_cb_t free_cb);
 
-- 
1.7.1




More information about the pulseaudio-discuss mailing list