Skip to content

Commit

Permalink
null out pointer after delete/free it
Browse files Browse the repository at this point in the history
  • Loading branch information
Piasy committed Jun 14, 2018
1 parent d1d2252 commit 4b0102d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ios_project/example/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ - (void)viewDidLoad {
}

- (void)doDecodeMono {
NSLog(@"doDecodeMono");
_testType = TEST_DECODE_MONO;

_sampleRate = 16000;
Expand All @@ -192,6 +193,7 @@ - (void)deliverMonoDecodedData:(void*)buf numFrames:(UInt32)numFrames {
}

- (void)doResample {
NSLog(@"doResample");
_testType = TEST_RESAMPLE;

_resamplerInputSampleRate = 44100;
Expand Down Expand Up @@ -246,6 +248,7 @@ - (void)deliverResampledData:(void*)buf numFrames:(UInt32)numFrames {
}

- (void)doDecodeAny {
NSLog(@"doDecodeAny");
_testType = TEST_DECODE_ANY;

_sampleRate = 48000;
Expand Down Expand Up @@ -286,6 +289,7 @@ - (void)deliverAnyDecodedData:(void*)buf numFrames:(UInt32)numFrames {
}

- (void)doMix {
NSLog(@"doMix");
_testType = TEST_MIX;

_sampleRate = 48000;
Expand Down Expand Up @@ -346,6 +350,7 @@ - (void)deliverMixedData:(void*)buf numFrames:(UInt32)numFrames {
}

- (void)doRecordAndMix {
NSLog(@"doRecordAndMix");
_testType = TEST_RECORD_AND_MIX;

_sampleRate = 48000;
Expand Down Expand Up @@ -425,6 +430,7 @@ - (void)deliverRecordAndMixedData:(void*)buf numFrames:(UInt32)numFrames {
}

- (void)doStopTest {
NSLog(@"doStopTest");
__weak ViewController* weakSelf = self;
dispatch_async(
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Expand All @@ -437,24 +443,31 @@ - (void)doStopTest {
}
if (strongSelf->_buffer) {
free(strongSelf->_buffer);
strongSelf->_buffer = nullptr;
}
if (strongSelf->_resamplerInputBuffer) {
free(strongSelf->_resamplerInputBuffer);
strongSelf->_resamplerInputBuffer = nullptr;
}
if (strongSelf->_decoder) {
delete strongSelf->_decoder;
strongSelf->_decoder = nullptr;
}
if (strongSelf->_resampler) {
delete strongSelf->_resampler;
strongSelf->_resampler = nullptr;
}
if (strongSelf->_source) {
delete strongSelf->_source;
strongSelf->_source = nullptr;
}
if (strongSelf->_resamplerReader) {
[strongSelf->_resamplerReader closeFile];
strongSelf->_resamplerReader = nil;
}
if (strongSelf->_recordAndMixDumper) {
[strongSelf->_recordAndMixDumper closeFile];
strongSelf->_recordAndMixDumper = nil;
}
});
}
Expand Down

0 comments on commit 4b0102d

Please sign in to comment.