ibsndfile versions 1.1.0 through 1.2.2 were affected by a memory leak in the sndfile-convert utility when encoding MP3 files.
The leak occurs in the error handling path of the MP3 encoder initialization logic, where resources allocated by lame_init() are not released when an early return is triggered.
This issue has already been fixed in the libsndfile project.
This document is provided for historical reference and traceability only.
Project: libsndfile
Tool: sndfile-convert
File: src/mpeg_l3_encode.c
Function: mpeg_l3_encoder_init
The root cause of the memory leak is an incomplete initialization sequence combined with early error returns.
In libsndfile/src/mpeg_l3_encode.c, the encoder context is allocated via lame_init(), but the corresponding cleanup callback (psf->codec_close) is not set immediately after successful allocation.
Relevant code path (pre-fix):
if (! (pmpeg->lamef = lame_init ()))
return SFE_MALLOC_FAILED ;
/* ... */
if (lame_set_out_samplerate (pmpeg->lamef, psf->sf.samplerate) < 0)
return SFE_MPEG_BAD_SAMPLERATE ;
/* codec_close is set only here */
psf->sf.seekable = 0 ;
psf->codec_close = mpeg_l3_encoder_close ;
psf->byterate = mpeg_l3_encoder_byterate ;
psf->datalength = 0 ;
return 0 ;-
lame_init() successfully allocates encoder resources.
-
lame_set_out_samplerate() fails due to an unsupported sample rate.
-
Function returns SFE_MPEG_BAD_SAMPLERATE.
-
Cleanup callback (psf->codec_close) has not yet been set.
-
Allocated encoder resources are not released, resulting in a memory leak.
This issue has been resolved in the official libsndfile repository.