|
Lines 46-62
Link Here
|
| 46 |
/* notes on macros: |
46 |
/* notes on macros: |
| 47 |
* having G_DISABLE_CHECKS defined disables use of glib_mem_profiler_table and |
47 |
* having G_DISABLE_CHECKS defined disables use of glib_mem_profiler_table and |
| 48 |
* g_mem_profile(). |
48 |
* g_mem_profile(). |
| 49 |
* If g_mem_gc_friendly is TRUE, freed memory should be 0-wiped. |
49 |
* REALLOC_0_WORKS is defined if g_realloc (NULL, x) works. |
|
|
50 |
* SANE_MALLOC_PROTOS is defined if the systems malloc() and friends functions |
| 51 |
* match the corresponding GLib prototypes, keep configure.ac and gmem.h in sync here. |
| 52 |
* g_mem_gc_friendly is TRUE, freed memory should be 0-wiped. |
| 50 |
*/ |
53 |
*/ |
| 51 |
|
54 |
|
|
|
55 |
/* --- malloc wrappers --- */ |
| 56 |
#ifndef REALLOC_0_WORKS |
| 57 |
static gpointer |
| 58 |
standard_realloc (gpointer mem, |
| 59 |
gsize n_bytes) |
| 60 |
{ |
| 61 |
if (!mem) |
| 62 |
return malloc (n_bytes); |
| 63 |
else |
| 64 |
return realloc (mem, n_bytes); |
| 65 |
} |
| 66 |
#endif /* !REALLOC_0_WORKS */ |
| 67 |
|
| 68 |
#ifdef SANE_MALLOC_PROTOS |
| 69 |
# define standard_malloc malloc |
| 70 |
# ifdef REALLOC_0_WORKS |
| 71 |
# define standard_realloc realloc |
| 72 |
# endif /* REALLOC_0_WORKS */ |
| 73 |
# define standard_free free |
| 74 |
# define standard_calloc calloc |
| 75 |
# define standard_try_malloc malloc |
| 76 |
# define standard_try_realloc realloc |
| 77 |
#else /* !SANE_MALLOC_PROTOS */ |
| 78 |
static gpointer |
| 79 |
standard_malloc (gsize n_bytes) |
| 80 |
{ |
| 81 |
return malloc (n_bytes); |
| 82 |
} |
| 83 |
# ifdef REALLOC_0_WORKS |
| 84 |
static gpointer |
| 85 |
standard_realloc (gpointer mem, |
| 86 |
gsize n_bytes) |
| 87 |
{ |
| 88 |
return realloc (mem, n_bytes); |
| 89 |
} |
| 90 |
# endif /* REALLOC_0_WORKS */ |
| 91 |
static void |
| 92 |
standard_free (gpointer mem) |
| 93 |
{ |
| 94 |
free (mem); |
| 95 |
} |
| 96 |
static gpointer |
| 97 |
standard_calloc (gsize n_blocks, |
| 98 |
gsize n_bytes) |
| 99 |
{ |
| 100 |
return calloc (n_blocks, n_bytes); |
| 101 |
} |
| 102 |
#define standard_try_malloc standard_malloc |
| 103 |
#define standard_try_realloc standard_realloc |
| 104 |
#endif /* !SANE_MALLOC_PROTOS */ |
| 105 |
|
| 106 |
|
| 52 |
/* --- variables --- */ |
107 |
/* --- variables --- */ |
| 53 |
static GMemVTable glib_mem_vtable = { |
108 |
static GMemVTable glib_mem_vtable = { |
| 54 |
malloc, |
109 |
standard_malloc, |
| 55 |
realloc, |
110 |
standard_realloc, |
| 56 |
free, |
111 |
standard_free, |
| 57 |
calloc, |
112 |
standard_calloc, |
| 58 |
malloc, |
113 |
standard_try_malloc, |
| 59 |
realloc, |
114 |
standard_try_realloc, |
| 60 |
}; |
115 |
}; |
| 61 |
|
116 |
|
| 62 |
/** |
117 |
/** |
|
Lines 566-573
profiler_log (ProfilerJob job,
Link Here
|
| 566 |
g_mutex_lock (&gmem_profile_mutex); |
621 |
g_mutex_lock (&gmem_profile_mutex); |
| 567 |
if (!profile_data) |
622 |
if (!profile_data) |
| 568 |
{ |
623 |
{ |
| 569 |
profile_data = calloc ((MEM_PROFILE_TABLE_SIZE + 1) * 8, |
624 |
profile_data = standard_calloc ((MEM_PROFILE_TABLE_SIZE + 1) * 8, |
| 570 |
sizeof (profile_data[0])); |
625 |
sizeof (profile_data[0])); |
| 571 |
if (!profile_data) /* memory system kiddin' me, eh? */ |
626 |
if (!profile_data) /* memory system kiddin' me, eh? */ |
| 572 |
{ |
627 |
{ |
| 573 |
g_mutex_unlock (&gmem_profile_mutex); |
628 |
g_mutex_unlock (&gmem_profile_mutex); |
|
Lines 766-772
profiler_free (gpointer mem)
Link Here
|
| 766 |
TRUE); |
821 |
TRUE); |
| 767 |
memset (p + 2, 0xaa, p[1]); |
822 |
memset (p + 2, 0xaa, p[1]); |
| 768 |
|
823 |
|
| 769 |
/* for all those that miss free (p); in this place, yes, |
824 |
/* for all those that miss standard_free (p); in this place, yes, |
| 770 |
* we do leak all memory when profiling, and that is intentional |
825 |
* we do leak all memory when profiling, and that is intentional |
| 771 |
* to catch double frees. patch submissions are futile. |
826 |
* to catch double frees. patch submissions are futile. |
| 772 |
*/ |
827 |
*/ |
|
Lines 793-799
profiler_try_realloc (gpointer mem,
Link Here
|
| 793 |
} |
848 |
} |
| 794 |
else |
849 |
else |
| 795 |
{ |
850 |
{ |
| 796 |
p = realloc (mem ? p : NULL, sizeof (gsize) * 2 + n_bytes); |
851 |
p = standard_realloc (mem ? p : NULL, sizeof (gsize) * 2 + n_bytes); |
| 797 |
|
852 |
|
| 798 |
if (p) |
853 |
if (p) |
| 799 |
{ |
854 |
{ |