@@ -192,9 +192,9 @@ static int memprof_enabled = 0;
192
192
static int memprof_dumped = 0 ;
193
193
static int track_mallocs = 0 ;
194
194
195
- static frame default_frame ;
196
- static frame * current_frame = & default_frame ;
197
- static alloc_list_head * current_alloc_list = & default_frame . allocs ;
195
+ static frame root_frame ;
196
+ static frame * current_frame ;
197
+ static alloc_list_head * current_alloc_list ;
198
198
static alloc_buckets current_alloc_buckets ;
199
199
200
200
static Pvoid_t allocs_set = (Pvoid_t ) NULL ;
@@ -245,9 +245,11 @@ static void alloc_check_single(alloc * alloc, const char * function, int line) {
245
245
static void alloc_check (alloc * alloc , const char * function , int line ) {
246
246
/* fprintf(stderr, "checking %p at %s:%d\n", alloc, function, line); */
247
247
alloc_check_single (alloc , function , line );
248
+ /*
248
249
for (alloc = current_alloc_list->lh_first; alloc; alloc = alloc->list.le_next) {
249
250
alloc_check_single(alloc, function, line);
250
251
}
252
+ */
251
253
}
252
254
253
255
# define ALLOC_CHECK (alloc ) alloc_check(alloc, __FUNCTION__, __LINE__);
@@ -262,7 +264,15 @@ static void alloc_buckets_destroy(alloc_buckets * buckets)
262
264
for (i = 0 ; i < buckets -> nbuckets ; ++ i ) {
263
265
free (buckets -> buckets [i ]);
264
266
}
267
+
268
+ #if MEMPROF_DEBUG
269
+ memset (buckets -> buckets , 0x5a , buckets -> nbuckets * sizeof (buckets -> buckets [0 ]));
270
+ #endif
265
271
free (buckets -> buckets );
272
+
273
+ #if MEMPROF_DEBUG
274
+ memset (buckets , 0x5a , sizeof (* buckets ));
275
+ #endif
266
276
}
267
277
268
278
static void alloc_buckets_grow (alloc_buckets * buckets )
@@ -321,6 +331,9 @@ static void destroy_frame(frame * f)
321
331
{
322
332
alloc * a ;
323
333
334
+ #if MEMPROF_DEBUG
335
+ memset (f -> name , 0x5a , f -> name_len );
336
+ #endif
324
337
free (f -> name );
325
338
326
339
while (f -> allocs .lh_first ) {
@@ -330,6 +343,10 @@ static void destroy_frame(frame * f)
330
343
}
331
344
332
345
zend_hash_destroy (& f -> next_cache );
346
+
347
+ #if MEMPROF_DEBUG
348
+ memset (f , 0x5a , sizeof (* f ));
349
+ #endif
333
350
}
334
351
335
352
/* HashTable destructor */
@@ -393,7 +410,7 @@ static int frame_stack_depth(const frame * f)
393
410
const frame * prev ;
394
411
int depth = 0 ;
395
412
396
- for (prev = f ; prev ; prev = prev -> prev ) {
413
+ for (prev = f ; prev != & root_frame ; prev = prev -> prev ) {
397
414
depth ++ ;
398
415
}
399
416
@@ -700,7 +717,7 @@ static PHP_INI_MH(OnChangeMemoryLimit)
700
717
701
718
ret = origOnChangeMemoryLimit (entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage );
702
719
703
- if (memprof_enabled ) {
720
+ if (memprof_enabled && orig_zheap ) {
704
721
zend_mm_set_heap (orig_zheap );
705
722
ret = zend_set_memory_limit (PG (memory_limit ));
706
723
zend_mm_set_heap (zheap );
@@ -713,8 +730,11 @@ static void memprof_enable()
713
730
{
714
731
alloc_buckets_init (& current_alloc_buckets );
715
732
716
- init_frame (& default_frame , NULL , "root" , sizeof ("root" )- 1 );
717
- default_frame .calls = 1 ;
733
+ init_frame (& root_frame , & root_frame , "root" , sizeof ("root" )- 1 );
734
+ root_frame .calls = 1 ;
735
+
736
+ current_frame = & root_frame ;
737
+ current_alloc_list = & root_frame .allocs ;
718
738
719
739
MALLOC_HOOK_SAVE_OLD ();
720
740
MALLOC_HOOK_SET_OWN ();
@@ -759,7 +779,7 @@ static void memprof_disable()
759
779
760
780
memprof_enabled = 0 ;
761
781
762
- destroy_frame (& default_frame );
782
+ destroy_frame (& root_frame );
763
783
764
784
alloc_buckets_destroy (& current_alloc_buckets );
765
785
@@ -1188,7 +1208,7 @@ static void dump_frames_pprof(php_stream * stream, HashTable * symbols, frame *
1188
1208
stream_write_word (stream , size );
1189
1209
stream_write_word (stream , stack_depth );
1190
1210
1191
- for (prev = f ; prev ; prev = prev -> prev ) {
1211
+ for (prev = f ; prev != & root_frame ; prev = prev -> prev ) {
1192
1212
zend_uintptr_t symaddr ;
1193
1213
symaddr = (zend_uintptr_t ) zend_hash_str_find_ptr (symbols , prev -> name , prev -> name_len );
1194
1214
if (symaddr == 0 ) {
@@ -1260,7 +1280,7 @@ PHP_FUNCTION(memprof_dump_array)
1260
1280
1261
1281
WITHOUT_MALLOC_TRACKING {
1262
1282
1263
- dump_frame_array (return_value , & default_frame );
1283
+ dump_frame_array (return_value , & root_frame );
1264
1284
1265
1285
} END_WITHOUT_MALLOC_TRACKING ;
1266
1286
@@ -1296,7 +1316,7 @@ PHP_FUNCTION(memprof_dump_callgrind)
1296
1316
stream_printf (stream , "events: MemorySize BlocksCount\n" );
1297
1317
stream_printf (stream , "\n" );
1298
1318
1299
- dump_frame_callgrind (stream , & default_frame , "root" , & total_size , & total_count );
1319
+ dump_frame_callgrind (stream , & root_frame , "root" , & total_size , & total_count );
1300
1320
1301
1321
stream_printf (stream , "total: %zu %zu\n" , total_size , total_count );
1302
1322
@@ -1333,7 +1353,7 @@ PHP_FUNCTION(memprof_dump_pprof)
1333
1353
1334
1354
stream_printf (stream , "--- symbol\n" );
1335
1355
stream_printf (stream , "binary=todo.php\n" );
1336
- dump_frames_pprof_symbols (stream , & symbols , & default_frame );
1356
+ dump_frames_pprof_symbols (stream , & symbols , & root_frame );
1337
1357
stream_printf (stream , "---\n" );
1338
1358
stream_printf (stream , "--- profile\n" );
1339
1359
@@ -1350,7 +1370,7 @@ PHP_FUNCTION(memprof_dump_pprof)
1350
1370
/* unused padding */
1351
1371
stream_write_word (stream , 0 );
1352
1372
1353
- dump_frames_pprof (stream , & symbols , & default_frame );
1373
+ dump_frames_pprof (stream , & symbols , & root_frame );
1354
1374
1355
1375
zend_hash_destroy (& symbols );
1356
1376
0 commit comments