From 9a34507023e1860a5af7d275246aea30046acbb4 Mon Sep 17 00:00:00 2001 From: Alexandre Lissy Date: Tue, 29 Sep 2020 15:13:40 +0200 Subject: [PATCH] Fix leak in C++ client --- native_client/client.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/native_client/client.cc b/native_client/client.cc index 96e1ff39..ff1f7b67 100644 --- a/native_client/client.cc +++ b/native_client/client.cc @@ -184,10 +184,12 @@ LocalDsSTT(ModelState* aCtx, const short* aBuffer, size_t aBufferSize, } size_t off = 0; const char *last = nullptr; + const char *prev = nullptr; while (off < aBufferSize) { size_t cur = aBufferSize - off > stream_size ? stream_size : aBufferSize - off; DS_FeedAudioContent(ctx, aBuffer + off, cur); off += cur; + prev = last; const char* partial = DS_IntermediateDecode(ctx); if (last == nullptr || strcmp(last, partial)) { printf("%s\n", partial); @@ -195,6 +197,9 @@ LocalDsSTT(ModelState* aCtx, const short* aBuffer, size_t aBufferSize, } else { DS_FreeString((char *) partial); } + if (prev != nullptr && prev != last) { + DS_FreeString((char *) prev); + } } if (last != nullptr) { DS_FreeString((char *) last);