fix StrStream memory leak

ISclose() doesn't free memory if a stream's function pointer, close, is NULL.
However, str_stream's close pointer is always NULL and thus leaks
memory.
This commit is contained in:
Kuang-che Wu
2021-10-26 15:45:06 +08:00
parent b201f426e4
commit b0ebd5737e

View File

@@ -185,12 +185,16 @@ int
ISclose(InputStream stream)
{
MySignalHandler(*prevtrap) ();
if (stream == NULL || stream->base.close == NULL ||
stream->base.type & IST_UNCLOSE)
return -1;
prevtrap = mySignal(SIGINT, SIG_IGN);
stream->base.close (stream->base.handle);
mySignal(SIGINT, prevtrap);
if (stream == NULL)
return -1;
if (stream->base.close != NULL) {
if (stream->base.type & IST_UNCLOSE) {
return -1;
}
prevtrap = mySignal(SIGINT, SIG_IGN);
stream->base.close (stream->base.handle);
mySignal(SIGINT, prevtrap);
}
xfree(stream->base.stream.buf);
xfree(stream);
return 0;