Hi,
I've been reading the bam's source tree lately and noticed a bit strange pattern:
- result of
malloc is rarely being checked, neither in the place where the call happens nor somewhere else.
- when memory needs to be zero-initialized the
malloc+memset is being used instead of calloc
For example:
|
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 ?
Hi,
I've been reading the bam's source tree lately and noticed a bit strange pattern:
mallocis rarely being checked, neither in the place where the call happens nor somewhere else.malloc+memsetis being used instead ofcallocFor example:
bam/src/statcache.c
Lines 28 to 35 in a44a2c7
In this case
sizeof(struct STATCACHE)is pretty big socallocwould 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?