summaryrefslogtreecommitdiff
path: root/src/malloc
diff options
context:
space:
mode:
Diffstat (limited to 'src/malloc')
-rw-r--r--src/malloc/free.c2
-rw-r--r--src/malloc/mallocng/aligned_alloc.c3
-rw-r--r--src/malloc/mallocng/free.c2
-rw-r--r--src/malloc/mallocng/glue.h8
-rw-r--r--src/malloc/mallocng/meta.h3
5 files changed, 13 insertions, 5 deletions
diff --git a/src/malloc/free.c b/src/malloc/free.c
index f17a952c..3944f7b2 100644
--- a/src/malloc/free.c
+++ b/src/malloc/free.c
@@ -2,5 +2,5 @@
void free(void *p)
{
- return __libc_free(p);
+ __libc_free(p);
}
diff --git a/src/malloc/mallocng/aligned_alloc.c b/src/malloc/mallocng/aligned_alloc.c
index 34116896..e0862a83 100644
--- a/src/malloc/mallocng/aligned_alloc.c
+++ b/src/malloc/mallocng/aligned_alloc.c
@@ -22,6 +22,9 @@ void *aligned_alloc(size_t align, size_t len)
if (align <= UNIT) align = UNIT;
unsigned char *p = malloc(len + align - UNIT);
+ if (!p)
+ return 0;
+
struct meta *g = get_meta(p);
int idx = get_slot_index(p);
size_t stride = get_stride(g);
diff --git a/src/malloc/mallocng/free.c b/src/malloc/mallocng/free.c
index 418a085c..43f32aad 100644
--- a/src/malloc/mallocng/free.c
+++ b/src/malloc/mallocng/free.c
@@ -119,7 +119,7 @@ void free(void *p)
if (((uintptr_t)(start-1) ^ (uintptr_t)end) >= 2*PGSZ && g->last_idx) {
unsigned char *base = start + (-(uintptr_t)start & (PGSZ-1));
size_t len = (end-base) & -PGSZ;
- if (len) {
+ if (len && USE_MADV_FREE) {
int e = errno;
madvise(base, len, MADV_FREE);
errno = e;
diff --git a/src/malloc/mallocng/glue.h b/src/malloc/mallocng/glue.h
index 151c48b8..c347a4ef 100644
--- a/src/malloc/mallocng/glue.h
+++ b/src/malloc/mallocng/glue.h
@@ -24,6 +24,8 @@
#define realloc __libc_realloc
#define free __libc_free
+#define USE_MADV_FREE 0
+
#if USE_REAL_ASSERT
#include <assert.h>
#else
@@ -34,8 +36,10 @@
#define brk(p) ((uintptr_t)__syscall(SYS_brk, p))
#define mmap __mmap
+#define munmap __munmap
#define madvise __madvise
#define mremap __mremap
+#define mprotect __mprotect
#define DISABLE_ALIGNED_ALLOC (__malloc_replaced && !__aligned_alloc_replaced)
@@ -60,8 +64,8 @@ __attribute__((__visibility__("hidden")))
extern int __malloc_lock[1];
#define LOCK_OBJ_DEF \
-int __malloc_lock[1]; \
-void __malloc_atfork(int who) { malloc_atfork(who); }
+void __malloc_atfork(int who) { malloc_atfork(who); } \
+int __malloc_lock[1]
static inline void rdlock()
{
diff --git a/src/malloc/mallocng/meta.h b/src/malloc/mallocng/meta.h
index 61ec53f9..3a27af64 100644
--- a/src/malloc/mallocng/meta.h
+++ b/src/malloc/mallocng/meta.h
@@ -129,12 +129,13 @@ static inline int get_slot_index(const unsigned char *p)
static inline struct meta *get_meta(const unsigned char *p)
{
assert(!((uintptr_t)p & 15));
- int offset = *(const uint16_t *)(p - 2);
+ size_t offset = *(const uint16_t *)(p - 2);
int index = get_slot_index(p);
if (p[-4]) {
assert(!offset);
offset = *(uint32_t *)(p - 8);
assert(offset > 0xffff);
+ assert(offset < PTRDIFF_MAX/UNIT);
}
const struct group *base = (const void *)(p - UNIT*offset - UNIT);
const struct meta *meta = base->meta;