[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] libpoke/ios-dev-stream.c: free buffer only in read mode
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH] libpoke/ios-dev-stream.c: free buffer only in read mode |
Date: |
Sat, 17 Oct 2020 12:23:12 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hi Mohammad.
> The `buffer` field of `struct ios_dev_stream` is only valid in
> read mode.
> ---
> libpoke/ios-dev-stream.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libpoke/ios-dev-stream.c b/libpoke/ios-dev-stream.c
> index 1258bfe5..0832011c 100644
> --- a/libpoke/ios-dev-stream.c
> +++ b/libpoke/ios-dev-stream.c
> @@ -118,7 +118,8 @@ ios_dev_stream_close (void *iod)
> {
> struct ios_dev_stream *sio = iod;
>
> - ios_buffer_free (sio->buffer);
> + if (sio->flags & IOS_F_READ)
> + ios_buffer_free (sio->buffer);
> free (sio);
>
> return 1;
Wouldn't it be better to make sure to initialize sio->buffer to NULL
when it is not used, and then to either:
1. Document (in ios-buffer.h) that ios_buffer_free works as a nop if
NULL is passed, or
2. Check for sio->buffer == NULL in ios_dev_stream_close and call (or
not) ios_buffer_free accordingly.