From 34f8678f1de4ef32c33071a0e8687108fec60823 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Thu, 19 Oct 2023 15:10:27 +0800 Subject: [PATCH] small fixes --- sherpa-onnx/c-api/c-api.cc | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/sherpa-onnx/c-api/c-api.cc b/sherpa-onnx/c-api/c-api.cc index 6ea06fac8..c07592e7d 100644 --- a/sherpa-onnx/c-api/c-api.cc +++ b/sherpa-onnx/c-api/c-api.cc @@ -206,12 +206,14 @@ const SherpaOnnxOnlineRecognizerResult *GetOnlineStreamResult( } void DestroyOnlineRecognizerResult(const SherpaOnnxOnlineRecognizerResult *r) { - delete[] r->text; - delete[] r->json; - delete[] r->tokens; - delete[] r->tokens_arr; - delete[] r->timestamps; - delete r; + if (r) { + delete[] r->text; + delete[] r->json; + delete[] r->tokens; + delete[] r->tokens_arr; + delete[] r->timestamps; + delete r; + } } void Reset(SherpaOnnxOnlineRecognizer *recognizer, @@ -387,9 +389,11 @@ const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult( void DestroyOfflineRecognizerResult( const SherpaOnnxOfflineRecognizerResult *r) { - delete[] r->text; - delete[] r->timestamps; - delete r; + if (r) { + delete[] r->text; + delete[] r->timestamps; + delete r; + } } // ============================================================ @@ -517,8 +521,10 @@ const SherpaOnnxSpeechSegment *SherpaOnnxVoiceActivityDetectorFront( } void SherpaOnnxDestroySpeechSegment(const SherpaOnnxSpeechSegment *p) { - delete[] p->samples; - delete p; + if (p) { + delete[] p->samples; + delete p; + } } void SherpaOnnxVoiceActivityDetectorReset(SherpaOnnxVoiceActivityDetector *p) { @@ -583,8 +589,10 @@ const SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerate( SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTtsGeneratedAudio( const SherpaOnnxGeneratedAudio *p) { - delete[] p->samples; - delete p; + if (p) { + delete[] p->samples; + delete p; + } } int32_t SherpaOnnxDestroyOfflineWriteWave(const SherpaOnnxGeneratedAudio *p,