/[path-sandbox]/trunk/libsandbox/memory.c
Gentoo

Diff of /trunk/libsandbox/memory.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 399 Revision 400
6 * Copyright 1999-2008 Gentoo Foundation 6 * Copyright 1999-2008 Gentoo Foundation
7 * Licensed under the GPL-2 7 * Licensed under the GPL-2
8 */ 8 */
9 9
10#include "headers.h" 10#include "headers.h"
11#include "libsandbox.h"
12#include "sbutil.h"
11 13
12#define SB_MALLOC_TO_MMAP(ptr) ((void*)(((size_t*)ptr) - 1)) 14#define SB_MALLOC_TO_MMAP(ptr) ((void*)(((size_t*)ptr) - 1))
13#define SB_MMAP_TO_MALLOC(ptr) ((void*)(((size_t*)ptr) + 1)) 15#define SB_MMAP_TO_MALLOC(ptr) ((void*)(((size_t*)ptr) + 1))
14#define SB_MALLOC_TO_SIZE(ptr) (*((size_t*)SB_MALLOC_TO_MMAP(ptr))) 16#define SB_MALLOC_TO_SIZE(ptr) (*((size_t*)SB_MALLOC_TO_MMAP(ptr)))
15 17
26 28
27void free(void *ptr) 29void free(void *ptr)
28{ 30{
29 if (ptr == NULL) 31 if (ptr == NULL)
30 return; 32 return;
31 munmap(SB_MALLOC_TO_MMAP(ptr), SB_MALLOC_TO_SIZE(ptr)); 33 if (munmap(SB_MALLOC_TO_MMAP(ptr), SB_MALLOC_TO_SIZE(ptr))) {
34 int color = ((is_env_on(ENV_NOCOLOR)) ? 0 : 1);
35 SB_EERROR(color, "sandbox memory corruption", " free(%p): %s\n",
36 ptr, strerror(errno));
37#ifdef HAVE_BACKTRACE
38 void *funcs[10];
39 int num_funcs;
40 num_funcs = backtrace(funcs, sizeof(funcs));
41 backtrace_symbols_fd(funcs, num_funcs, STDERR_FILENO);
42#endif
43 }
32} 44}
33 45
34void *calloc(size_t nmemb, size_t size) 46void *calloc(size_t nmemb, size_t size)
35{ 47{
36 void *ret; 48 void *ret;
61 memcpy(ret, ptr, MIN(size, old_malloc_size)); 73 memcpy(ret, ptr, MIN(size, old_malloc_size));
62 free(ptr); 74 free(ptr);
63 return ret; 75 return ret;
64} 76}
65 77
66#ifdef strdup
67#undef strdup
68#endif
69char *strdup(const char *s) 78char *strdup(const char *s)
70{ 79{
71 size_t len; 80 size_t len;
72 char *ret; 81 char *ret;
73 82

Legend:
Removed from v.399  
changed lines
  Added in v.400

  ViewVC Help
Powered by ViewVC 1.1.20