X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmalloc%2Fmalloc.c;h=39c7d05188ce7fc516e312f348dcfb9b688bf3e0;hb=4f346b08b33c9265c36fe8a14f5f908b1a9f296a;hp=db4287ef061127bbb49714733d53389d4ea6569f;hpb=5d0965cb56f92e24b36b98882543f8ee1e03b5ff;p=musl diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index db4287ef..39c7d051 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -43,8 +43,8 @@ static struct { #define DONTCARE 16 #define RECLAIM 163840 -#define CHUNK_SIZE(c) ((c)->csize & SIZE_MASK) -#define CHUNK_PSIZE(c) ((c)->psize & SIZE_MASK) +#define CHUNK_SIZE(c) ((c)->csize & -2) +#define CHUNK_PSIZE(c) ((c)->psize & -2) #define PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c))) #define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c))) #define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD) @@ -52,8 +52,6 @@ static struct { #define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head)) #define C_INUSE ((size_t)1) -#define C_FLAGS ((size_t)3) -#define C_SIZE SIZE_MASK #define IS_MMAPPED(c) !((c)->csize & (C_INUSE)) @@ -394,7 +392,7 @@ void *realloc(void *p, size_t n) size_t oldlen = n0 + extra; size_t newlen = n + extra; /* Crash on realloc of freed chunk */ - if ((uintptr_t)base < mal.brk) *(volatile char *)0=0; + if (extra & 1) a_crash(); if (newlen < PAGE_SIZE && (new = malloc(n))) { memcpy(new, p, n-OVERHEAD); free(p); @@ -457,7 +455,7 @@ void free(void *p) char *base = (char *)self - extra; size_t len = CHUNK_SIZE(self) + extra; /* Crash on double free */ - if ((uintptr_t)base < mal.brk) *(volatile char *)0=0; + if (extra & 1) a_crash(); __munmap(base, len); return; }