DeepSpeech icon indicating copy to clipboard operation
DeepSpeech copied to clipboard

Swift Client: Fix double deallocation

Open weipin opened this issue 4 years ago • 3 comments

Hello,

This PR is an attempt to fix a double deallocation issue in the Swift client.

How to produce

  1. In the Swift demo project deepspeech_ios_test, locate the file SpeechRecognitionImpl.swift, and replace let result = stream.finishStream() with let result = stream.finishStreamWithMetadata(numResults: 1)
  2. Run the app and click the button "Recognize files".
  3. The app will crash as soon as the associated DeepSpeechStream is deallocated. In my case, Xcode prompted something like "Thread XXX: Deallocation of freed memory".

References

  • @zaptrem also mentioned a similar issue in https://github.com/mozilla/DeepSpeech/issues/3061#issuecomment-776199055: "I'm using intermediateDecodeWithMetadata as finishStreamWithMetadata also has an unknown crash".

Fix

Seems the fix can be as simple as adding one line of code. After the patch, the code pattern of finishStreamWithMetadata(numResults:) now aligns with finishStream().

Thank you

Would like to thank @reuben for the Swift wrapper-related work!

weipin avatar Jun 27 '21 04:06 weipin

Could you please consider merging this, @reuben? Thanks!

JanX2 avatar Aug 14 '21 14:08 JanX2

I no longer have push access to this repository. If you can open the PR against our coqui-ai/STT fork I'm happy to merge it.

reuben avatar Aug 14 '21 16:08 reuben

Few weeks ago I was planning to do that (opening a PR against coqui). But failed to build the iOS static framework -- bazel prompts:

"ERROR: file 'native_client/libkenlm.so' is generated by these conflicting actions:".

Will give it another try later.

weipin avatar Aug 15 '21 03:08 weipin