Skip to content

Commit d8b5f18

Browse files
committed
zmalloc Solaris fixes thanks to Alan Harder
1 parent 6e333bb commit d8b5f18

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

zmalloc.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
#include <string.h>
3434
#include "config.h"
3535

36+
#if defined(__sun)
37+
#define PREFIX_SIZE sizeof(long long)
38+
#else
39+
#define PREFIX_SIZE sizeof(size_t)
40+
#endif
41+
3642
static size_t used_memory = 0;
3743

3844
static void zmalloc_oom(size_t size) {
@@ -43,16 +49,16 @@ static void zmalloc_oom(size_t size) {
4349
}
4450

4551
void *zmalloc(size_t size) {
46-
void *ptr = malloc(size+sizeof(size_t));
52+
void *ptr = malloc(size+PREFIX_SIZE);
4753

4854
if (!ptr) zmalloc_oom(size);
4955
#ifdef HAVE_MALLOC_SIZE
5056
used_memory += redis_malloc_size(ptr);
5157
return ptr;
5258
#else
5359
*((size_t*)ptr) = size;
54-
used_memory += size+sizeof(size_t);
55-
return (char*)ptr+sizeof(size_t);
60+
used_memory += size+PREFIX_SIZE;
61+
return (char*)ptr+PREFIX_SIZE;
5662
#endif
5763
}
5864

@@ -73,15 +79,15 @@ void *zrealloc(void *ptr, size_t size) {
7379
used_memory += redis_malloc_size(newptr);
7480
return newptr;
7581
#else
76-
realptr = (char*)ptr-sizeof(size_t);
82+
realptr = (char*)ptr-PREFIX_SIZE;
7783
oldsize = *((size_t*)realptr);
78-
newptr = realloc(realptr,size+sizeof(size_t));
84+
newptr = realloc(realptr,size+PREFIX_SIZE);
7985
if (!newptr) zmalloc_oom(size);
8086

8187
*((size_t*)newptr) = size;
8288
used_memory -= oldsize;
8389
used_memory += size;
84-
return (char*)newptr+sizeof(size_t);
90+
return (char*)newptr+PREFIX_SIZE;
8591
#endif
8692
}
8793

@@ -96,9 +102,9 @@ void zfree(void *ptr) {
96102
used_memory -= redis_malloc_size(ptr);
97103
free(ptr);
98104
#else
99-
realptr = (char*)ptr-sizeof(size_t);
105+
realptr = (char*)ptr-PREFIX_SIZE;
100106
oldsize = *((size_t*)realptr);
101-
used_memory -= oldsize+sizeof(size_t);
107+
used_memory -= oldsize+PREFIX_SIZE;
102108
free(realptr);
103109
#endif
104110
}

0 commit comments

Comments
 (0)