Merge pull request #59 from redboltz/add_null_check

Added null pointer check.
This commit is contained in:
Takatoshi Kondo 2014-01-27 17:53:19 -08:00
commit 9eb4583dd5
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)
{
msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)malloc(sizeof(msgpack_vrefbuffer));
if (vbuf == NULL) return NULL;
if(!msgpack_vrefbuffer_init(vbuf, ref_size, chunk_size)) {
free(vbuf);
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* zbuf = (msgpack_zbuffer*)malloc(sizeof(msgpack_zbuffer));
if (zbuf == NULL) return NULL;
if(!msgpack_zbuffer_init(zbuf, level, init_size)) {
free(zbuf);
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(
sizeof(msgpack_zone_chunk) + sz);
if (chunk == NULL) return NULL;
char* ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk);
if (ptr == NULL) {
free(chunk);
return NULL;
}
chunk->next = cl->head;
cl->head = chunk;
cl->free = sz - size;