From 14ccf213b4eb26887bbe696ed812384f8896975b Mon Sep 17 00:00:00 2001 From: BrunoBerisso Date: Tue, 14 Jul 2015 16:57:55 -0300 Subject: [PATCH] Decoder - Fix crash when stopDecodingSpeech() is called - Remove the ps_free() from the assert. It was causing memory leak in reals builds --- TLSphinx/Decoder.swift | 6 ++---- TLSphinxTests/LiveDecode.swift | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/TLSphinx/Decoder.swift b/TLSphinx/Decoder.swift index 512aa23..4877e9e 100644 --- a/TLSphinx/Decoder.swift +++ b/TLSphinx/Decoder.swift @@ -55,10 +55,10 @@ public class Decoder { } deinit { - assert(ps_free(psDecoder) == 0, "Can't free decoder, it's shared among instances") + let refCount = ps_free(psDecoder) + assert(refCount == 0, "Can't free decoder, it's shared among instances") } - private func process_raw(data: NSData) -> CInt { //Sphinx expect words of 2 bytes but the NSFileHandle read one byte at time so the lenght of the data for sphinx is the half of the real one. let dataLenght = data.length / 2 @@ -204,8 +204,6 @@ public class Decoder { public func stopDecodingSpeech () { recorder.stop() - end_utt() - recorder.deleteRecording() recorder = nil } diff --git a/TLSphinxTests/LiveDecode.swift b/TLSphinxTests/LiveDecode.swift index 9cfbd98..82ff395 100644 --- a/TLSphinxTests/LiveDecode.swift +++ b/TLSphinxTests/LiveDecode.swift @@ -26,7 +26,9 @@ class LiveDecode: XCTestCase { let dict = modelPath.stringByAppendingPathComponent("cmudict-en-us.dict") if let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) { + config.showDebugInfo = false + if let decoder = Decoder(config:config) { decoder.startDecodingSpeech { (hyp) -> () in println("Utterance: \(hyp)")