Added null pointer check.

This commit is contained in:
Takatoshi Kondo 2014-01-28 10:54:57 +09:00
parent 8bc827ebf5
commit 5a23c86dc1
3 changed files with 7 additions and 2 deletions

View File

@ -98,6 +98,7 @@ void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vref);
static inline msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size) static inline msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size)
{ {
msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)malloc(sizeof(msgpack_vrefbuffer)); msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)malloc(sizeof(msgpack_vrefbuffer));
if (vbuf == NULL) return NULL;
if(!msgpack_vrefbuffer_init(vbuf, ref_size, chunk_size)) { if(!msgpack_vrefbuffer_init(vbuf, ref_size, chunk_size)) {
free(vbuf); free(vbuf);
return NULL; return NULL;

View File

@ -91,6 +91,7 @@ void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf)
msgpack_zbuffer* msgpack_zbuffer_new(int level, size_t init_size) msgpack_zbuffer* msgpack_zbuffer_new(int level, size_t init_size)
{ {
msgpack_zbuffer* zbuf = (msgpack_zbuffer*)malloc(sizeof(msgpack_zbuffer)); msgpack_zbuffer* zbuf = (msgpack_zbuffer*)malloc(sizeof(msgpack_zbuffer));
if (zbuf == NULL) return NULL;
if(!msgpack_zbuffer_init(zbuf, level, init_size)) { if(!msgpack_zbuffer_init(zbuf, level, init_size)) {
free(zbuf); free(zbuf);
return NULL; return NULL;

View File

@ -84,9 +84,12 @@ void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size)
msgpack_zone_chunk* chunk = (msgpack_zone_chunk*)malloc( msgpack_zone_chunk* chunk = (msgpack_zone_chunk*)malloc(
sizeof(msgpack_zone_chunk) + sz); sizeof(msgpack_zone_chunk) + sz);
if (chunk == NULL) return NULL;
char* ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk); char* ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk);
if (ptr == NULL) {
free(chunk);
return NULL;
}
chunk->next = cl->head; chunk->next = cl->head;
cl->head = chunk; cl->head = chunk;
cl->free = sz - size; cl->free = sz - size;