Skip to content

Commit

Permalink
Merge pull request mozilla#3351 from lissyx/leak-intermediate-decode
Browse files Browse the repository at this point in the history
Fix leak in C++ client
  • Loading branch information
lissyx authored Sep 29, 2020
2 parents 0c020d1 + 9a34507 commit f20f939
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions native_client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,22 @@ 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);
last = partial;
} else {
DS_FreeString((char *) partial);
}
if (prev != nullptr && prev != last) {
DS_FreeString((char *) prev);
}
}
if (last != nullptr) {
DS_FreeString((char *) last);
Expand Down

0 comments on commit f20f939

Please sign in to comment.