00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00039 #ifndef _malloc_h_
00040 #define _malloc_h_
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #if defined(USE_DMALLOC) && defined(TRACK_MALLOC)
00053 #error "TRACK_MALLOC and USE_DMALLOC are mutually exclusive"
00054 #endif
00055
00056 #ifdef MALLOC_STATS
00057 #ifndef TRACK_MALLOC
00058 #define TRACK_MALLOC
00059 #endif
00060 #endif
00061
00062 #if defined(TRACK_MALLOC) && !defined(MALLOC_SOURCE)
00063
00064 #include "hashlist.h"
00065
00066 #undef strdup
00068 #define malloc(s) malloc_track((s), _WHERE_, __LINE__)
00069 #define calloc(n,s) malloc0_track((n)*(s), _WHERE_, __LINE__)
00070 #define free(o) free_track(o, _WHERE_, __LINE__)
00071 #define realloc(o,s) realloc_track(o, (s), _WHERE_, __LINE__)
00072 #define strdup(s) strdup_track((s), _WHERE_, __LINE__)
00073 #define strndup(s,n) strndup_track((s), (n), _WHERE_, __LINE__)
00074
00075 #define g_malloc(s) malloc_track((s), _WHERE_, __LINE__)
00076 #define g_malloc0(s) malloc0_track((s), _WHERE_, __LINE__)
00077 #define g_free(o) free_track(o, _WHERE_, __LINE__)
00078 #define g_realloc(o,s) realloc_track(o, (s), _WHERE_, __LINE__)
00079 #define g_strdup(s) ((s) ? strdup_track(s, _WHERE_, __LINE__) : 0)
00080 #define g_strndup(s,n) ((s) ? strndup_track(s, (n), _WHERE_, __LINE__) : 0)
00081 #define g_strjoinv(s,v) strjoinv_track(s, (v), _WHERE_, __LINE__)
00082 #define g_memdup(p,s) ((p) ? memdup_track((p), (s), _WHERE_, __LINE__) : 0)
00083 #define g_strfreev(v) strfreev_track((v), _WHERE_, __LINE__)
00084
00085 #undef g_new
00086 #undef g_new0
00087 #undef g_renew
00088
00089 #define g_new(t,c) (t*) malloc_track(sizeof(t)*(c), _WHERE_, __LINE__)
00090 #define g_new0(t,c) (t*) malloc0_track(sizeof(t)*(c), _WHERE_, __LINE__)
00091 #define g_renew(t,m,c) (t*) realloc_track((m),sizeof(t)*(c),_WHERE_,__LINE__)
00092
00093 #define g_strconcat(s, ...) \
00094 strconcat_track(_WHERE_, __LINE__, s, __VA_ARGS__)
00095
00096 #define g_strdup_printf(fmt, ...) \
00097 strdup_printf_track(_WHERE_, __LINE__, fmt, __VA_ARGS__)
00098
00099 #define g_strsplit(s,d,m) strsplit_track((s),(d),(m), _WHERE_, __LINE__)
00100
00101 #define g_hash_table_new(x,y) hashtable_new_track(x, y, _WHERE_, __LINE__)
00102 #define g_hash_table_destroy(x) hashtable_destroy_track(x, _WHERE_, __LINE__)
00103
00104 #define hash_list_new() hash_list_new_track(_WHERE_, __LINE__)
00105 #define hash_list_free(h) hash_list_free_track((h), _WHERE_, __LINE__)
00106
00107 #define g_slist_alloc() slist_alloc_track(_WHERE_, __LINE__)
00108 #define g_slist_append(l,d) slist_append_track((l),(d), _WHERE_, __LINE__)
00109 #define g_slist_prepend(l,d) slist_prepend_track((l),(d), _WHERE_, __LINE__)
00110 #define g_slist_copy(l) slist_copy_track((l), _WHERE_, __LINE__)
00111 #define g_slist_free(l) slist_free_track((l), _WHERE_, __LINE__)
00112 #define g_slist_free_1(l) slist_free1_track((l), _WHERE_, __LINE__)
00113 #define g_slist_remove(l,d) slist_remove_track((l),(d), _WHERE_, __LINE__)
00114
00115 #define g_slist_insert(l,d,p) \
00116 slist_insert_track((l),(d),(p), _WHERE_, __LINE__)
00117 #define g_slist_insert_sorted(l,d,c) \
00118 slist_insert_sorted_track((l),(d),(c), _WHERE_, __LINE__)
00119 #define gm_slist_insert_after(l,lk,d) \
00120 slist_insert_after_track((l),(lk),(d), _WHERE_, __LINE__)
00121
00122 #define g_list_alloc() list_alloc_track(_WHERE_, __LINE__)
00123 #define g_list_append(l,d) list_append_track((l),(d), _WHERE_, __LINE__)
00124 #define g_list_prepend(l,d) list_prepend_track((l),(d), _WHERE_, __LINE__)
00125 #define g_list_copy(l) list_copy_track((l), _WHERE_, __LINE__)
00126 #define g_list_free(l) list_free_track((l), _WHERE_, __LINE__)
00127 #define g_list_free_1(l) list_free1_track((l), _WHERE_, __LINE__)
00128 #define g_list_remove(l,d) list_remove_track((l),(d), _WHERE_, __LINE__)
00129
00130 #define g_list_insert(l,d,p) \
00131 list_insert_track((l),(d),(p), _WHERE_, __LINE__)
00132 #define g_list_insert_sorted(l,d,c) \
00133 list_insert_sorted_track((l),(d),(c), _WHERE_, __LINE__)
00134 #define gm_list_insert_after(l,lk,d) \
00135 list_insert_after_track((l),(lk),(d), _WHERE_, __LINE__)
00136 #define g_list_delete_link(l,lk) \
00137 list_delete_link_track((l),(lk), _WHERE_, __LINE__)
00138
00139 #define g_string_new(p) string_new_track((p), _WHERE_, __LINE__)
00140 #define g_string_sized_new(s) string_sized_new_track((s), _WHERE_, __LINE__)
00141 #define g_string_append(s,p) string_append_track((s),(p),_WHERE_,__LINE__)
00142 #define g_string_append_c(s,c) string_append_c_track((s),(c),_WHERE_,__LINE__)
00143 #define g_string_assign(s,p) string_assign_track((s),(p),_WHERE_,__LINE__)
00144 #define g_string_free(s,b) string_free_track((s),(b), _WHERE_, __LINE__)
00145 #define g_string_prepend(s,p) string_prepend_track((s),(p),_WHERE_,__LINE__)
00146 #define g_string_prepend_c(s,c) string_prepend_c_track(s),(c),_WHERE_,__LINE__)
00147
00148 #define g_string_append_len(s,v,l) \
00149 string_append_len_track((s),(v),(l),_WHERE_,__LINE__)
00150 #define g_string_insert(s,i,p) \
00151 string_insert_track((s),(i),(p),_WHERE_,__LINE__)
00152 #define g_string_insert_c(s,i,c) \
00153 string_insert_c_track((s),(i),(c),_WHERE_,__LINE__)
00154
00155 #ifdef USE_GTK2
00156 #undef g_string_sprintf
00157 #undef g_string_sprintfa
00158 #endif
00159 #define g_string_sprintf(s,fmt,...) \
00160 string_sprintf_track((s),_WHERE_,__LINE__,(fmt), __VA_ARGS__)
00161 #define g_string_sprintfa(s,fmt,...) \
00162 string_sprintf_tracka((s),_WHERE_,__LINE__,(fmt), __VA_ARGS__)
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 #define STRTRACK(s) string_record((s), _WHERE_, __LINE__)
00175 #define MEMTRACK(o,s) malloc_record((o), (s), _WHERE_, __LINE__)
00176
00177 #else
00178
00179 #define STRTRACK(s) s
00180 #define MEMTRACK(o,s) o
00181
00182 #endif
00183
00184 #if defined(TRACK_MALLOC) || defined(MALLOC_SOURCE)
00185
00186 gpointer string_record(const gchar *s, gchar *file, gint line);
00187 gpointer malloc_record(gpointer o, guint32 s, gchar *file, gint line);
00188
00189 gpointer malloc_track(guint32 s, gchar *file, gint line);
00190 gpointer malloc0_track(guint32 s, gchar *file, gint line);
00191 void free_track(gpointer o, gchar *file, gint line);
00192 void strfreev_track(gchar **v, gchar *file, gint line);
00193 gpointer realloc_track(gpointer o, guint32 s, gchar *file, gint line);
00194 gchar *strdup_track(const gchar *s, gchar *file, gint line);
00195 gchar *strndup_track(const gchar *s, gint n, gchar *file, gint line);
00196 gpointer memdup_track(gconstpointer p, guint size, gchar *file, gint line);
00197 gchar *strjoinv_track(const gchar *s, gchar **vec, gchar *file, gint line);
00198 gchar *strconcat_track(gchar *file, gint line, const gchar *s, ...);
00199 gchar *strdup_printf_track(gchar *file, gint line, const gchar *fmt, ...)
00200 G_GNUC_PRINTF(3, 4);
00201 gchar **strsplit_track(
00202 const gchar *s, const gchar *d, gint m, gchar *file, gint line);
00203
00204 GHashTable *hashtable_new_track(
00205 GHashFunc h, GCompareFunc y, gchar *file, gint line);
00206 void hashtable_destroy_track(GHashTable *h, gchar *file, gint line);
00207
00208 hash_list_t *hash_list_new_track(gchar *file, gint line);
00209 void hash_list_free_track(hash_list_t *h, gchar *file, gint line);
00210
00211 GSList *slist_alloc_track(gchar *file, gint line);
00212 GSList *slist_append_track(GSList *l, gpointer data, gchar *file, gint line);
00213 GSList *slist_prepend_track(GSList *l, gpointer data, gchar *file, gint line);
00214 GSList *slist_copy_track(GSList *l, gchar *file, gint line);
00215 void slist_free_track(GSList *l, gchar *file, gint line);
00216 void slist_free1_track(GSList *l, gchar *file, gint line);
00217 GSList *slist_remove_track(GSList *l, gpointer data, gchar *file, gint line);
00218 GSList *slist_insert_track(
00219 GSList *l, gpointer d, gint pos, gchar *file, gint line);
00220 GSList *slist_insert_sorted_track(
00221 GSList *l, gpointer d, GCompareFunc c, gchar *file, gint line);
00222 GSList *slist_insert_after_track(
00223 GSList *l, GSList *lk, gpointer data, gchar *file, gint line);
00224
00225 GList *list_alloc_track(gchar *file, gint line);
00226 GList *list_append_track(GList *l, gpointer data, gchar *file, gint line);
00227 GList *list_prepend_track(GList *l, gpointer data, gchar *file, gint line);
00228 GList *list_copy_track(GList *l, gchar *file, gint line);
00229 void list_free_track(GList *l, gchar *file, gint line);
00230 void list_free1_track(GList *l, gchar *file, gint line);
00231 GList *list_remove_track(GList *l, gpointer data, gchar *file, gint line);
00232 GList *list_insert_track(
00233 GList *l, gpointer d, gint pos, gchar *file, gint line);
00234 GList *list_insert_sorted_track(
00235 GList *l, gpointer d, GCompareFunc c, gchar *file, gint line);
00236 GList *list_insert_after_track(
00237 GList *l, GList *lk, gpointer data, gchar *file, gint line);
00238 GList *list_delete_link_track(GList *l, GList *lk, gchar *file, gint line);
00239
00240 GString *string_new_track(const gchar *p, gchar *file, gint line);
00241 GString *string_sized_new_track(guint size, gchar *file, gint line);
00242 GString *string_append_track(
00243 GString *s, const gchar *p, gchar *file, gint line);
00244 GString *string_append_c_track(
00245 GString *s, gchar c, gchar *file, gint line);
00246 GString *string_append_len_track(
00247 GString *s, const gchar *val, gssize len, gchar *file, gint line);
00248 GString *string_assign_track(
00249 GString *s, const gchar *p, gchar *file, gint line);
00250 void string_free_track(GString *s, gint freestr, gchar *file, gint line);
00251 GString *string_prepend_track(
00252 GString *s, const gchar *p, gchar *file, gint line);
00253 GString *string_prepend_c_track(
00254 GString *s, gchar c, gchar *file, gint line);
00255 GString *string_insert_track(
00256 GString *s, gint pos, const gchar *p, gchar *file, gint line);
00257 GString *string_insert_c_track(
00258 GString *s, gint pos, gchar c, gchar *file, gint line);
00259 GString *string_sprintf_track(
00260 GString *s, gchar *file, gint line, const gchar *fmt, ...)
00261 G_GNUC_PRINTF(4, 5);
00262 GString *string_sprintfa_track(
00263 GString *s, gchar *file, gint line, const gchar *fmt, ...)
00264 G_GNUC_PRINTF(4, 5);
00265
00266 #endif
00267
00268 #ifdef TRACK_MALLOC
00269 void malloc_close(void);
00270 #endif
00271
00272 #if defined(TRACK_MALLOC) || defined(TRACK_ZALLOC)
00273
00274 gpointer leak_init(void);
00275 void leak_add(gpointer o, guint32 size, gchar *file, gint line);
00276 void leak_dump(gpointer o);
00277 void leak_close(gpointer o);
00278
00279 #endif
00280
00281 #ifdef MALLOC_STATS
00282 void alloc_dump(FILE *f, gboolean total);
00283 void alloc_reset(FILE *f, gboolean total);
00284 #endif
00285
00286 #endif
00287