Module: sip-router
Branch: master
Commit: f61ff34aac7c7bae3a96fb698a899c8a0e692a9f
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f61ff34…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Mon Dec 2 20:42:12 2013 +0100
mem: malloc(0) should return a valid pointer for free according to specs
---
mem/f_malloc.c | 2 ++
mem/q_malloc.c | 2 ++
2 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/mem/f_malloc.c b/mem/f_malloc.c
index 008874b..7a0e115 100644
--- a/mem/f_malloc.c
+++ b/mem/f_malloc.c
@@ -361,6 +361,8 @@ void* fm_malloc(struct fm_block* qm, unsigned long size)
MDBG("fm_malloc(%p, %lu) called from %s: %s(%d)\n", qm, size, file, func,
line);
#endif
+ /*malloc(0) should return a valid pointer according to specs*/
+ if(unlikely(size==0)) size=4;
/*size must be a multiple of 8*/
size=ROUNDUP(size);
/* if (size>(qm->size-qm->real_used)) return 0; */
diff --git a/mem/q_malloc.c b/mem/q_malloc.c
index bfa46fd..50acab9 100644
--- a/mem/q_malloc.c
+++ b/mem/q_malloc.c
@@ -368,6 +368,8 @@ void* qm_malloc(struct qm_block* qm, unsigned long size)
MDBG("qm_malloc(%p, %lu) called from %s: %s(%d)\n", qm, size, file, func,
line);
#endif
+ /*malloc(0) should return a valid pointer according to specs*/
+ if(unlikely(size==0)) size=4;
/*size must be a multiple of 8*/
size=ROUNDUP(size);
if (size>(qm->size-qm->real_used)) return 0;