[Home]

Summary:ASTERISK-12742: freeing unused memory in ast_get_enum
Reporter:pj (pj)Labels:
Date Opened:2008-09-16 16:35:53Date Closed:2008-09-17 15:15:57
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Functions/func_enum
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) 13498.patch
Description:I found some incorrect memory handling in enum.c,
every time asterisk invoke ENUMLOOKUP() function,
it generates following warnings in mmlog:
WARNING: Freeing unused memory at (nil), in ast_get_enum of enum.c, line 897
WARNING: Freeing unused memory at (nil), in ast_get_enum of enum.c, line 897
WARNING: Freeing unused memory at (nil), in ast_get_enum of enum.c, line 897
WARNING: Freeing unused memory at (nil), in ast_get_enum of enum.c, line 897
WARNING: Freeing unused memory at (nil), in ast_get_enum of enum.c, line 897

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

function use example:
Set(dial_string=SIP/${ENUMLOOKUP(${num},sip,,1,e164.arpa.)});
Comments:By: pj (pj) 2008-09-16 16:47:09

maybe it's only cosmetic thing, I open this bugreport according to recommendation by jpeeler, in ASTERISK-12610

By: Mark Michelson (mmichelson) 2008-09-17 09:34:12

I agree that this is mostly a cosmetic thing. Freeing a NULL pointer has no ill effects, but the memory-manager used when compiling with MALLOC_DEBUG raises a warning because that block is not one of its allocated regions. Perhaps astmm.c should be modified so that that warning is supressed if the equivalent of free(NULL) is issued.

By: pj (pj) 2008-09-17 12:43:28

it would be good to stop logging this unnecesary warnings (if it's trivial to do), it will help to keep mmlog clean, where will stay only really problematic memory handlings in asterisk.

By: Mark Michelson (mmichelson) 2008-09-17 14:06:53

Wow, not only is it trivial, it looks like this will actually make freeing a NULL pointer more efficient since we won't have to do any hashtable lookups for the allocated region. I'm going to attach a patch. Please give it a try. I'm confident that it will do what is desired, but it never hurts to test.

By: Mark Michelson (mmichelson) 2008-09-17 14:09:07

Please give 13498.patch a try. Thanks!

By: pj (pj) 2008-09-17 14:49:14

SVN-trunk-r143340 + 13498.patch
mmlog is clean and no other problems appears, if you think, that your patch can't have any negative side effect, it could be commited soon, thanks!

By: Digium Subversion (svnbot) 2008-09-17 15:15:56

Repository: asterisk
Revision: 143400

U   trunk/main/astmm.c

------------------------------------------------------------------------
r143400 | mmichelson | 2008-09-17 15:15:55 -0500 (Wed, 17 Sep 2008) | 16 lines

If attempting to free a NULL pointer when MALLOC_DEBUG
is set, don't bother searching for a region to free, just
immediately exit.

This has the dual benefit of suppressing a warning message
about freeing memory at (nil) and of optimizing the free()
replacement by not having to do any futile searching for
the proper region to free.

(closes issue ASTERISK-12742)
Reported by: pj
Patches:
     13498.patch uploaded by putnopvut (license 60)
Tested by: pj


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

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