summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/lib/mpmalloc.h1
-rw-r--r--src/lib/mpmalloc.cc20
-rw-r--r--src/lib/ubjson/ubjr.c7
3 files changed, 22 insertions, 6 deletions
diff --git a/include/lib/mpmalloc.h b/include/lib/mpmalloc.h
index 0699042..4f1bb47 100644
--- a/include/lib/mpmalloc.h
+++ b/include/lib/mpmalloc.h
@@ -7,6 +7,7 @@ extern "C" {
void* mpcalloc(size_t nmemb, size_t size);
void* mpmalloc(size_t size);
+void* mprealloc(void* addr, size_t size);
void mpfree(void* addr);
#ifdef __cplusplus
diff --git a/src/lib/mpmalloc.cc b/src/lib/mpmalloc.cc
index db4a87a..2483a3a 100644
--- a/src/lib/mpmalloc.cc
+++ b/src/lib/mpmalloc.cc
@@ -2,7 +2,8 @@
#include "driver/stdout.h"
#include "lib/mpmalloc.h"
-void* mpcalloc(size_t nmemb, size_t size) {
+void* mpcalloc(size_t nmemb, size_t size)
+{
void* ret = calloc(nmemb, size);
#ifdef ADDR_20BIT
kout << "calloc:" << dec << (uint32_t)nmemb << "x" << (uint32_t)size << "@" << ret << endl;
@@ -12,7 +13,8 @@ void* mpcalloc(size_t nmemb, size_t size) {
return ret;
}
-void* mpmalloc(size_t size) {
+void* mpmalloc(size_t size)
+{
void* ret = malloc(size);
#ifdef ADDR_20BIT
kout << "malloc:" << dec << (uint32_t)size << "@" << ret << endl;
@@ -22,7 +24,19 @@ void* mpmalloc(size_t size) {
return ret;
}
-void mpfree(void* addr) {
+void* mprealloc(void* addr, size_t size)
+{
+ void* ret = realloc(addr, size);
+#ifdef ADDR_20BIT
+ kout << "realloc:" << addr << ":" << dec << (uint32_t)size << "@" << ret << endl;
+#else
+ kout << "realloc:" << addr << ":" << dec << size << "@" << ret << endl;
+#endif
+ return ret;
+}
+
+void mpfree(void* addr)
+{
kout << "free:" << addr << endl;
free(addr);
}
diff --git a/src/lib/ubjson/ubjr.c b/src/lib/ubjson/ubjr.c
index e45bd95..7bb2b2f 100644
--- a/src/lib/ubjson/ubjr.c
+++ b/src/lib/ubjson/ubjr.c
@@ -7,6 +7,7 @@
#include "lib/mpmalloc.h"
#else
#define mpmalloc malloc
+#define mprealloc realloc
#define mpfree free
#endif
@@ -370,7 +371,7 @@ static inline ubjr_array_t priv_ubjr_read_raw_array(ubjr_context_t* ctx)
if (myarray.size >= (1ULL << arrpot))
{
arrpot ++;
- myarray.values = realloc(myarray.values, (1ULL << arrpot)*ls+1);
+ myarray.values = mprealloc(myarray.values, (1ULL << arrpot)*ls+1);
}
priv_ubjr_read_to_ptr(ctx,(uint8_t*)myarray.values + ls*myarray.size,myarray.type);
}
@@ -422,8 +423,8 @@ static inline ubjr_object_t priv_ubjr_read_raw_object(ubjr_context_t* ctx)
if (myobject.size >= (1ULL << arrpot))
{
arrpot++;
- myobject.values = realloc(myobject.values, (1ULL << arrpot)*ls + 1);
- myobject.keys = realloc((uint8_t*)myobject.keys, (1ULL << arrpot)*sizeof(ubjr_string_t));
+ myobject.values = mprealloc(myobject.values, (1ULL << arrpot)*ls + 1);
+ myobject.keys = mprealloc((uint8_t*)myobject.keys, (1ULL << arrpot)*sizeof(ubjr_string_t));
}
priv_ubjr_read_to_ptr(ctx, (uint8_t*)(myobject.keys + myobject.size), UBJ_STRING);
priv_ubjr_read_to_ptr(ctx, (uint8_t*)myobject.values + ls*myobject.size, myobject.type);