mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 13:49:17 +02:00
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:
parent
b6ba47c2e3
commit
9ed2f9a27a
1 changed files with 5 additions and 11 deletions
16
sexp.c
16
sexp.c
|
@ -140,22 +140,16 @@ 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)))
|
&& !sexp_port_customp(port)
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
#if SEXP_USE_STRING_STREAMS
|
free(sexp_port_buf(port));
|
||||||
&& !sexp_port_customp(port)
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
free(sexp_port_buf(port));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue