Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit f20f939

Browse files
authored
Merge pull request #3351 from lissyx/leak-intermediate-decode
Fix leak in C++ client
2 parents 0c020d1 + 9a34507 commit f20f939

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

native_client/client.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,22 @@ LocalDsSTT(ModelState* aCtx, const short* aBuffer, size_t aBufferSize,
184184
}
185185
size_t off = 0;
186186
const char *last = nullptr;
187+
const char *prev = nullptr;
187188
while (off < aBufferSize) {
188189
size_t cur = aBufferSize - off > stream_size ? stream_size : aBufferSize - off;
189190
DS_FeedAudioContent(ctx, aBuffer + off, cur);
190191
off += cur;
192+
prev = last;
191193
const char* partial = DS_IntermediateDecode(ctx);
192194
if (last == nullptr || strcmp(last, partial)) {
193195
printf("%s\n", partial);
194196
last = partial;
195197
} else {
196198
DS_FreeString((char *) partial);
197199
}
200+
if (prev != nullptr && prev != last) {
201+
DS_FreeString((char *) prev);
202+
}
198203
}
199204
if (last != nullptr) {
200205
DS_FreeString((char *) last);

0 commit comments

Comments
 (0)