Fixing memory leak in string ports found by Lorenzo.

In the future this will be simplified by dropping support for
C string streams and never using malloc for buffers.
This commit is contained in:
Alex Shinn 2012-11-23 11:17:08 +09:00
parent b6ba47c2e3
commit 9ed2f9a27a

10
sexp.c
View file

@ -140,23 +140,17 @@ sexp sexp_finalize_port (sexp ctx, sexp self, sexp_sint_t n, sexp port) {
} }
} }
#endif #endif
if (sexp_port_stream(port) && ! sexp_port_no_closep(port)) { if (sexp_port_stream(port) && ! sexp_port_no_closep(port))
/* close the stream */ /* close the stream */
fclose(sexp_port_stream(port)); fclose(sexp_port_stream(port));
/* free the buffer if allocated */ /* free the buffer if allocated */
if (sexp_port_buf(port) if (sexp_port_buf(port) && sexp_oportp(port)
&& (sexp_oportp(port)
#if !SEXP_USE_STRING_STREAMS #if !SEXP_USE_STRING_STREAMS
|| (sexp_iportp(port) && sexp_truep(sexp_port_cookie(port)))
#endif
)
#if SEXP_USE_STRING_STREAMS
&& !sexp_port_customp(port) && !sexp_port_customp(port)
#endif #endif
) )
free(sexp_port_buf(port)); free(sexp_port_buf(port));
} }
}
return res; return res;
} }