audiod: Fix memory leak in writer setup.
authorAndre Noll <maan@systemlinux.org>
Sat, 6 Aug 2011 19:44:24 +0000 (21:44 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 13 Aug 2011 10:59:28 +0000 (12:59 +0200)
If no writers are given, the default writer is used for each supported
audio format. In this case, we called the writer's command line parser
on each open, rather than once at startup as we fo for the non-default
case. This resulted in a memory leak which is fixed in this patch by
setting up the default writer only once, in the same way the default
receivers and filters are set up.

audiod.c

index c7998cd..74aa386 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -522,16 +522,12 @@ static void open_writers(struct slot_info *s)
        assert(s->wns == NULL);
        s->wns = para_calloc(PARA_MAX(1U, a->num_writers)
                * sizeof(struct writer_node));
-       if (a->num_writers == 0)
-               setup_writer_node(NULL, parent, s->wns);
-       else {
-               PARA_INFO_LOG("opening %s writers\n", audio_formats[s->format]);
-               for (i = 0; i < a->num_writers; i++) {
-                       wn = s->wns + i;
-                       wn->conf = a->writer_conf[i];
-                       wn->writer_num = a->writer_nums[i];
-                       register_writer_node(wn, parent);
-               }
+       PARA_INFO_LOG("opening %s writers\n", audio_formats[s->format]);
+       for (i = 0; i < a->num_writers; i++) {
+               wn = s->wns + i;
+               wn->conf = a->writer_conf[i];
+               wn->writer_num = a->writer_nums[i];
+               register_writer_node(wn, parent);
        }
 }
 
@@ -800,6 +796,20 @@ static int parse_writer_args(void)
                        a->num_writers++;
                }
        }
+       /* Use default writer for audio formats which are not yet set up. */
+       FOR_EACH_AUDIO_FORMAT(i) {
+               struct writer *w = writers + DEFAULT_WRITER;
+               a = afi + i;
+               if (a->num_writers > 0)
+                       continue; /* already set up */
+               PARA_INFO_LOG("%s writer: %s (default)\n", audio_formats[i],
+                       writer_names[DEFAULT_WRITER]);
+               a->writer_nums = para_malloc(sizeof(int));
+               a->writer_nums[0] = DEFAULT_WRITER;
+               a->writer_conf = para_malloc(sizeof(void *));
+               a->writer_conf[0] = w->parse_config_or_die("");
+               a->num_writers = 1;
+       }
        ret = 1;
 out:
        return ret;