[Home]

Summary:ASTERISK-13039: [patch] Fix a memory leak while trying to free a memory that wasn't allocated by ast_alloc_region()
Reporter:Eliel Sardanons (eliel)Labels:
Date Opened:2008-11-07 21:56:15.000-0600Date Closed:2008-11-10 12:04:26.000-0600
Priority:MinorRegression?No
Status:Closed/CompleteComponents:General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) readline.c.patch
Description:This leak occurs if MALLOC_DEBUG is *enabled*

function filename_completion_function() inside complete_fn() (main/cli.c) is returning a memory not allocated by ast_alloc_region() if MALLOC_DEBUG is enabled, and we are trying to free it with a call to ast_free_region(), so the pointer is not found and not freed.

The solution could be to let readline.c allocate the memory with ast_alloc_region() (#include "asterisk.h"), the problem is that we must be sure that we will not free memory allocated in this manner from other part of 'editline', cause we will generate another memory leak (though).

Other thing could be to not set free() to ast_free() so we will be able to handle this situations with a call to free() (right now being replaced to a call to ast_free()) when we know that the source of the pointer is "in some point" external to asterisk.

****** ADDITIONAL INFORMATION ******

To reproduce this leak, compile asterisk with MALLOC_DEBUG, and then connect to the CLI and do:
CLI*> module load <TAB TAB>       <--- For autocompletion
And you will see a lot of "WARNING: Freeing unused memory at ..."
Comments:By: Digium Subversion (svnbot) 2008-11-10 12:04:26.000-0600

Repository: asterisk
Revision: 155763

U   trunk/main/editline/readline.c

------------------------------------------------------------------------
r155763 | tilghman | 2008-11-10 12:04:25 -0600 (Mon, 10 Nov 2008) | 6 lines

Fix memory leak when MALLOC_DEBUG is enabled.
(closes issue ASTERISK-13039)
Reported by: eliel
Patches:
      readline.c.patch uploaded by eliel (license 64)

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=155763