[Home]

Summary:ASTERISK-24348: Built-in editline tab complete segfault with MALLOC_DEBUG
Reporter:Walter Doekes (wdoekes)Labels:
Date Opened:2014-09-22 12:34:53Date Closed:2014-09-22 12:44:08
Priority:MajorRegression?Yes
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description:When MALLOC_DEBUG is enabled, the builtin editline uses the asterisk malloc and friends, not the default libc ones:

{noformat}
------------------------------------------------------------------------
r155763 | tilghman | 2008-11-10 19:04:30 +0100 (ma, 10 nov 2008) | 6 lines

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

------------------------------------------------------------------------
Index: main/editline/readline.c
===================================================================
--- main/editline/readline.c (revision 155762)
+++ main/editline/readline.c (revision 155763)
@@ -36,6 +36,7 @@
 * POSSIBILITY OF SUCH DAMAGE.
 */

+#include "asterisk.h"
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
__RCSID("$NetBSD: readline.c,v 1.21 2002/03/18 16:20:36 christos Exp $");
{noformat}

But then we attempt to free the memory with ast_std_free (the libc one):

{noformat}
------------------------------------------------------------------------
r421600 | rmudgett | 2014-08-21 00:13:44 +0200 (do, 21 aug 2014) | 6 lines

cli.c: Fix tab completion of "module load" when MALLOC_DEBUG is enabled.

filename_completion_function() returns memory that was not allocated by
the MALLOC_DEBUG allocation tracker so the memory must be freed by
ast_std_free().

------------------------------------------------------------------------
Index: main/cli.c
===================================================================
--- main/cli.c (revision 421599)
+++ main/cli.c (revision 421600)
@@ -241,7 +241,7 @@ static char *complete_fn(const char *word, int sta
if (c)
c = ast_strdup(c);

- free(d);
+ ast_std_free(d);

return c;
}
{noformat}

155763 should've been reverted when 421600 was fixed.

P.S. Why do we define `free` as `ast_free`? Shouldn't we define it as `ast_throw_error` instead?
Comments: