-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Description
Hi,
I've been reading the bam's source tree lately and noticed a bit strange pattern:
- result of
mallocis rarely being checked, neither in the place where the call happens nor somewhere else. - when memory needs to be zero-initialized the
malloc+memsetis being used instead ofcalloc
For example:
Lines 28 to 35 in a44a2c7
| struct STATCACHE* statcache_create() | |
| { | |
| struct STATCACHE* statcache = malloc(sizeof(struct STATCACHE)); | |
| memset(statcache, 0, sizeof(struct STATCACHE)); | |
| statcache->heap = mem_create(); | |
| return statcache; | |
| } |
In this case sizeof(struct STATCACHE) is pretty big so calloc would be beneficial.
(see https://stackoverflow.com/questions/2688466/why-mallocmemset-is-slower-than-calloc )
Also, in OOM situation, this will corrupt memory and cause a crash later.
Is there a reason for this? Are there any platforms that do not support calloc ?
Metadata
Metadata
Assignees
Labels
No labels