Fix a memory leak in the ALAC decoder.
authorJuho Vähä-Herttua <juhovh@iki.fi>
Wed, 21 Mar 2012 12:01:35 +0000 (14:01 +0200)
committerJuho Vähä-Herttua <juhovh@iki.fi>
Wed, 16 May 2012 21:33:32 +0000 (00:33 +0300)
src/lib/alac/alac.c
src/lib/alac/alac.h
src/lib/raop_buffer.c

index 9d575ae6b2e47ec6ebdb4ad52c64c3e612f4a267..195e66afd0de62ca9a364c345811e790129571aa 100644 (file)
@@ -111,6 +111,24 @@ static void allocate_buffers(alac_file *alac)
        alac->uncompressed_bytes_buffer_b = malloc(alac->setinfo_max_samples_per_frame * 4);
 }
 
+static void deallocate_buffers(alac_file *alac)
+{
+    free(alac->predicterror_buffer_a);
+    free(alac->predicterror_buffer_b);
+    alac->predicterror_buffer_a = NULL;
+    alac->predicterror_buffer_b = NULL;
+
+    free(alac->outputsamples_buffer_a);
+    free(alac->outputsamples_buffer_b);
+    alac->outputsamples_buffer_a = NULL;
+    alac->outputsamples_buffer_b = NULL;
+       
+       free(alac->uncompressed_bytes_buffer_a);
+       free(alac->uncompressed_bytes_buffer_b);
+       alac->uncompressed_bytes_buffer_a = NULL;
+       alac->uncompressed_bytes_buffer_b = NULL;
+}
+
 void alac_set_info(alac_file *alac, char *inputbuffer)
 {
   char *ptr = inputbuffer;
@@ -1170,3 +1188,9 @@ alac_file *create_alac(int samplesize, int numchannels)
     return newfile;
 }
 
+void destroy_alac(alac_file *alac)
+{
+    if (!alac) return;
+    deallocate_buffers(alac);
+    free(alac);
+}
index 23dbc52779f4f96a8cb194c938d8145fc9ac439d..e5bf814342ceece6ba63731311ca6655aa969a4b 100644 (file)
@@ -8,6 +8,7 @@ void decode_frame(alac_file *alac,
                   unsigned char *inbuffer,
                   void *outbuffer, int *outputsize);
 void alac_set_info(alac_file *alac, char *inputbuffer);
+void destroy_alac(alac_file *alac);
 
 #endif /* __ALAC__DECOMP_H */
 
index b9b52afa2feb6929368933bd8d4a6833f6c0e129..7869d1d53c5d59fd597b7b1159acb50573a0c206 100644 (file)
@@ -211,8 +211,8 @@ void
 raop_buffer_destroy(raop_buffer_t *raop_buffer)
 {
        if (raop_buffer) {
+               destroy_alac(raop_buffer->alac);
                free(raop_buffer->buffer);
-               free(raop_buffer->alac);
                free(raop_buffer);
        }
 }