Skip to content

Commit 6ca6869

Browse files
chzhij5txfelixzhou
authored andcommitted
Hotfix/0.5.x (Tencent#226)
* fix trace build bug * fix CheckedDatabaseListActivity 兼容性crash * try catch OutOfMemoryError * fix npe * fix permission crash * 1. style check 2. upload 0.5.2 to jcenter 3. add ‘armeabi’ back to abiFilters * Dev (Tencent#208) * fix trace build bug (Tencent#199) * Hotfix/0.5.x (Tencent#200) * fix trace build bug * fix CheckedDatabaseListActivity 兼容性crash * Hotfix/0.5.x to dev (Tencent#207) * fix trace build bug * fix CheckedDatabaseListActivity 兼容性crash * try catch OutOfMemoryError * fix npe * fix permission crash * 1. style check 2. upload 0.5.2 to jcenter 3. add ‘armeabi’ back to abiFilters * fix(MemStat): USE_PRIVATE_API access nil pointer * fix(MemStat): do not “update_object_event” for g_matrix_block_monitor_dumping_thread_id * fix(MemStat): do not log the oc’event of dumping thread * fix(CrashBlock): free g_topStackAddressRepeatArray
1 parent 8623c49 commit 6ca6869

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

matrix/matrix-iOS/Matrix/WCCrashBlockMonitor/CrashBlockPlugin/Main/BlockMonitor/Handler/WCMainThreadHandler.mm

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,29 @@ - (id)init
6868
return [self initWithCycleArrayCount:10];
6969
}
7070

71-
- (void)freeMainThreadCycleArray
71+
- (void)dealloc
7272
{
7373
for (uint32_t i = 0; i < m_cycleArrayCount; i++) {
7474
if (g_mainThreadStackCycleArray[i] != NULL) {
7575
free(g_mainThreadStackCycleArray[i]);
7676
g_mainThreadStackCycleArray[i] = NULL;
7777
}
7878
}
79-
free(g_mainThreadStackCycleArray);
80-
g_mainThreadStackCycleArray = NULL;
81-
}
82-
- (void)dealloc
83-
{
84-
[self freeMainThreadCycleArray];
85-
free(g_mainThreadStackCount);
79+
80+
if (g_mainThreadStackCycleArray != NULL) {
81+
free(g_mainThreadStackCycleArray);
82+
g_mainThreadStackCycleArray = NULL;
83+
}
84+
85+
if (g_mainThreadStackCount != NULL) {
86+
free(g_mainThreadStackCount);
87+
g_mainThreadStackCount = NULL;
88+
}
89+
90+
if (g_topStackAddressRepeatArray != NULL) {
91+
free(g_topStackAddressRepeatArray);
92+
g_topStackAddressRepeatArray = NULL;
93+
}
8694
}
8795

8896
- (void)addThreadStack:(uintptr_t *)stackArray andStackCount:(size_t)stackCount

matrix/matrix-iOS/Matrix/WCMemoryStat/MemoryLogger/ObjectEvent/nsobject_hook.mm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
#import <objc/runtime.h>
1919
#import "nsobject_hook.h"
2020
#import "object_event_handler.h"
21+
#include <pthread/pthread.h>
2122

2223
#if __has_feature(objc_arc)
2324
#error This file must be compiled with MRR. Use -fno-objc-arc flag.
2425
#endif
2526

27+
extern mach_port_t g_matrix_block_monitor_dumping_thread_id;
28+
2629
#pragma mark -
2730
#pragma mark NSObject ObjectEventLogging
2831

@@ -37,7 +40,10 @@ @implementation NSObject (ObjectEventLogging)
3740
+ (id)event_logging_alloc
3841
{
3942
id object = [self event_logging_alloc];
40-
nsobject_set_last_allocation_event_name(object, class_getName(self.class));
43+
if (pthread_mach_thread_np(pthread_self()) == g_matrix_block_monitor_dumping_thread_id) {
44+
return object;
45+
}
46+
nsobject_set_last_allocation_event_name(object, class_getName(self.class));
4147
return object;
4248
}
4349

matrix/matrix-iOS/Matrix/WCMemoryStat/MemoryLogger/ObjectEvent/object_event_handler.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#pragma mark -
2929
#pragma mark Types
3030

31+
#ifdef DEBUG
32+
#define USE_PRIVATE_API
33+
#endif
34+
3135
struct object_type {
3236
uint32_t type;
3337
char name[59];
@@ -385,9 +389,15 @@ bool prepare_object_event_logger(const char *log_dir)
385389

386390
void disable_object_event_logger()
387391
{
388-
*object_set_last_allocation_event_name_funcion = NULL;
389-
*object_record_allocation_event_enable = false;
392+
#ifdef USE_PRIVATE_API
393+
if (object_set_last_allocation_event_name_funcion != NULL) {
394+
*object_set_last_allocation_event_name_funcion = NULL;
395+
}
396+
if (object_record_allocation_event_enable != NULL) {
397+
*object_record_allocation_event_enable = false;
398+
}
390399
//nsobject_hook_alloc_method();
400+
#endif
391401
}
392402

393403
object_type_file *open_object_type_file(const char *event_dir)

matrix/matrix-iOS/Matrix/WCMemoryStat/MemoryLogger/memory_logging.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
#include "dyld_image_info.h"
4242
#include "stack_frames_db.h"
4343

44+
#ifdef DEBUG
45+
#define USE_PRIVATE_API
46+
#endif
47+
4448
#pragma mark -
4549
#pragma mark Constants/Globals
4650

@@ -202,7 +206,8 @@ void __memory_event_callback(uint32_t type_flags, uintptr_t zone_ptr, uintptr_t
202206

203207
void __update_object_event(uint64_t address, uint32_t new_type)
204208
{
205-
if (current_thread_id() == working_thread_id || !logging_is_enable) {
209+
thread_id curr_thread = current_thread_id();
210+
if (curr_thread == working_thread_id || curr_thread == g_matrix_block_monitor_dumping_thread_id || !logging_is_enable) {
206211
return;
207212
}
208213

@@ -518,7 +523,11 @@ void disable_memory_logging(void)
518523

519524
disable_object_event_logger();
520525
malloc_logger = NULL;
521-
*syscall_logger = NULL;
526+
#ifdef USE_PRIVATE_API
527+
if (syscall_logger != NULL) {
528+
*syscall_logger = NULL;
529+
}
530+
#endif
522531
// avoid that after the memory monitoring stops, there are still some events being written.
523532
reset_write_index(event_buffer);
524533
// make current logging invalid

0 commit comments

Comments
 (0)