src/flac.c: Fix a memory leak 16/211316/1
authorErik de Castro Lopo <erikd@mega-nerd.com>
Wed, 12 Apr 2017 09:10:40 +0000 (19:10 +1000)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 1 Aug 2019 09:01:21 +0000 (18:01 +0900)
The pflac->rbuffer pointer array was being allocated in two
places, but only one of them (the one that was kept) was checking
to ensure the pointers were NULL before allocation.

Leak was found by fuzzing the sndfile-resample binary compiled
with ASAN.

Change-Id: Ie5bafb97aeefc38afbb13f3ac668ccbc34da986c

src/flac.c

index 6bd8aae..b74ada1 100644 (file)
@@ -430,8 +430,7 @@ sf_flac_meta_get_vorbiscomments (SF_PRIVATE *psf, const FLAC__StreamMetadata *me
 static void
 sf_flac_meta_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC__StreamMetadata *metadata, void *client_data)
 {      SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-       FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-       int bitwidth = 0, i ;
+       int bitwidth = 0 ;
 
        switch (metadata->type)
        {       case FLAC__METADATA_TYPE_STREAMINFO :
@@ -468,12 +467,6 @@ sf_flac_meta_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC_
 
                        if (bitwidth > 0)
                                psf_log_printf (psf, "  Bit width   : %d\n", bitwidth) ;
-
-
-                       for (i = 0 ; i < psf->sf.channels ; i++)
-                               pflac->rbuffer [i] = calloc (FLAC__MAX_BLOCK_SIZE, sizeof (int32_t)) ;
-
-                       pflac->wbuffer = (const int32_t* const*) pflac->rbuffer ;
                        break ;
 
                case FLAC__METADATA_TYPE_VORBIS_COMMENT :