Merge pull request #3351 from lissyx/leak-intermediate-decode
Fix leak in C++ client
This commit is contained in:
commit
f20f939ade
|
@ -184,10 +184,12 @@ LocalDsSTT(ModelState* aCtx, const short* aBuffer, size_t aBufferSize,
|
||||||
}
|
}
|
||||||
size_t off = 0;
|
size_t off = 0;
|
||||||
const char *last = nullptr;
|
const char *last = nullptr;
|
||||||
|
const char *prev = nullptr;
|
||||||
while (off < aBufferSize) {
|
while (off < aBufferSize) {
|
||||||
size_t cur = aBufferSize - off > stream_size ? stream_size : aBufferSize - off;
|
size_t cur = aBufferSize - off > stream_size ? stream_size : aBufferSize - off;
|
||||||
DS_FeedAudioContent(ctx, aBuffer + off, cur);
|
DS_FeedAudioContent(ctx, aBuffer + off, cur);
|
||||||
off += cur;
|
off += cur;
|
||||||
|
prev = last;
|
||||||
const char* partial = DS_IntermediateDecode(ctx);
|
const char* partial = DS_IntermediateDecode(ctx);
|
||||||
if (last == nullptr || strcmp(last, partial)) {
|
if (last == nullptr || strcmp(last, partial)) {
|
||||||
printf("%s\n", partial);
|
printf("%s\n", partial);
|
||||||
|
@ -195,6 +197,9 @@ LocalDsSTT(ModelState* aCtx, const short* aBuffer, size_t aBufferSize,
|
||||||
} else {
|
} else {
|
||||||
DS_FreeString((char *) partial);
|
DS_FreeString((char *) partial);
|
||||||
}
|
}
|
||||||
|
if (prev != nullptr && prev != last) {
|
||||||
|
DS_FreeString((char *) prev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (last != nullptr) {
|
if (last != nullptr) {
|
||||||
DS_FreeString((char *) last);
|
DS_FreeString((char *) last);
|
||||||
|
|
Loading…
Reference in New Issue