Add checks for NULL return from gc_*

This commit is contained in:
iabdalkader 2014-03-01 13:35:26 +02:00
parent b21018f39e
commit 41936ff96a
2 changed files with 11 additions and 12 deletions

View File

@ -1,23 +1,19 @@
#include <libmp.h>
#include "xalloc.h"
#define BREAK() __asm__ volatile ("BKPT");
void *xcalloc(size_t nmemb, size_t size)
void *xalloc(size_t size)
{
void *mem = gc_alloc(nmemb*size);
if (mem) {
bzero(mem, nmemb*size);
void *mem = gc_alloc(size);
if (mem == NULL) {
BREAK();
}
return mem;
}
void *xalloc(size_t size)
{
return gc_alloc(size);
}
void *xalloc0(size_t size)
{
void *mem = gc_alloc(size);
void *mem = xalloc(size);
if (mem) {
bzero(mem, size);
}
@ -31,6 +27,10 @@ void xfree(void *ptr)
void *xrealloc(void *ptr, size_t size)
{
return gc_realloc(ptr, size);
ptr = gc_realloc(ptr, size);
if (ptr == NULL) {
BREAK();
}
return ptr;
}

View File

@ -1,7 +1,6 @@
#ifndef __XALLOC_H__
#define __XALLOC_H__
#include <stdint.h>
void *xcalloc(size_t nmemb, size_t size);
void *xalloc(size_t size);
void *xalloc0(size_t size);
void xfree(void *ptr);