[Asterisk-code-review] core: Stop using AST INLINE API for allocator functions. (asterisk[master])

Richard Mudgett asteriskteam at digium.com
Wed Mar 14 14:35:09 CDT 2018


Richard Mudgett has posted comments on this change. ( https://gerrit.asterisk.org/8521 )

Change subject: core: Stop using AST_INLINE_API for allocator functions.
......................................................................


Patch Set 2: Code-Review-1

(5 comments)

__ast_calloc() is NOT the same as calloc().

https://gerrit.asterisk.org/#/c/8521/2/include/asterisk/astmm.h
File include/asterisk/astmm.h:

https://gerrit.asterisk.org/#/c/8521/2/include/asterisk/astmm.h@55
PS2, Line 55: void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc;
            : void *__ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc;
            : void *__ast_malloc(size_t size, const char *file, int lineno, const char *func) attribute_malloc;
            : void __ast_free(void *ptr, const char *file, int lineno, const char *func);
            : void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
            : char *__ast_strdup(const char *s, const char *file, int lineno, const char *func) attribute_malloc;
            : char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func) attribute_malloc;
            : int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
            : 	__attribute__((format(printf, 5, 6)));
            : int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
            : 	__attribute__((format(printf, 2, 0)));
You need both __ast_repl_calloc() and __ast_calloc() prototype versions declared here.


https://gerrit.asterisk.org/#/c/8521/2/include/asterisk/astmm.h@134
PS2, Line 134: 	__ast_calloc(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
__ast_calloc() is NOT the same as calloc().  __ast_calloc() also checks and logs allocation failures using Asterisk's logging system.

When MALLOC_DEBUG is enabled the replacement calloc() (__ast_repl_calloc()) logs to MALLOC_DEBUG's logger for debugging purposes not Asterisk's logging system.


https://gerrit.asterisk.org/#/c/8521/2/main/astmm.c
File main/astmm.c:

https://gerrit.asterisk.org/#/c/8521/2/main/astmm.c@1557
PS2, Line 1557: void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
You have reverted part of the improvement I did with the always MALLOC_DEBUG API change.  __ast_calloc() called __ast_repl_calloc() where __ast_repl_calloc() is either the standard calloc or the MALLOC_DEBUG calloc replacement.

* The primary reason for __ast_calloc() being different from __ast_repl_calloc() is when MALLOC_DEBUG is enabled it would still check and give the MALLOC_FAILURE_MSG log when the code called __ast_calloc().

* DEBUG_CHAOS is again incompatible with MALLOC_DEBUG.  (Which I just found out that menuselect should have been updated to remove the conflicts with MALLOC_DEBUG restraint. :) )


https://gerrit.asterisk.org/#/c/8521/2/third-party/pjproject/patches/asterisk_malloc_debug.h
File third-party/pjproject/patches/asterisk_malloc_debug.h:

https://gerrit.asterisk.org/#/c/8521/2/third-party/pjproject/patches/asterisk_malloc_debug.h@28
PS2, Line 28: int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
            : 	__attribute__((format(printf, 5, 6)));
            : void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
            : void __ast_free(void *ptr, const char *file, int lineno, const char *func);
            : void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);
            : void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
            : char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);
            : char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);
            : int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
            : 	__attribute__((format(printf, 2, 0)));
Restore the __ast_repl_xxx prototypes.  Should add the attribute_malloc though.


https://gerrit.asterisk.org/#/c/8521/2/utils/Makefile
File utils/Makefile:

https://gerrit.asterisk.org/#/c/8521/2/utils/Makefile@103
PS2, Line 103: astman.o: _ASTCFLAGS+=-DNO_MALLOC_DEBUG
This is where NO_MALLOC_DEBUG is defined.  NO_MALLOC_DEBUG doesn't seem needed anymore in the code.  The only place it would have an effect now is in astmm.c and it is never set there.



-- 
To view, visit https://gerrit.asterisk.org/8521
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: If9df4377f74bdbb627461b27a473123e05525887
Gerrit-Change-Number: 8521
Gerrit-PatchSet: 2
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
Gerrit-Comment-Date: Wed, 14 Mar 2018 19:35:09 +0000
Gerrit-HasComments: Yes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180314/ce66cdf1/attachment-0001.html>


More information about the asterisk-code-review mailing list