[FFmpeg-devel] [PATCH v2] libavformat/ftp: Do not leak memory in routine ftp_features
Alexander Strasser
eclipse7 at gmx.net
Tue Aug 26 01:03:47 CEST 2014
On 2014-08-21 23:02 +0200, Alexander Strasser wrote:
> Setting the pointer to NULL inside both ftp_send_command
> and ftp_features is redundant. Generally always setting to
> NULL in ftp_send_command seems safer, but throughout the file
> that parameter was always passed initialized. So I do it here
> too for consistency.
>
> Should fix CID1231988 (RESOURCE_LEAK)
>
> Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
> ---
>
> I tested with valgrind and the mem leak goes away. About the
> rest it would be good if someone could have a 2nd look.
>
> And maybe Lukasz can comment if he finds some time because he
> maintains this code.
Received an OK from Lukasz in private.
Pushed.
Thanks for having a look Lukasz,
Alexander
> libavformat/ftp.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/ftp.c b/libavformat/ftp.c
> index 9ee9b16..7faf4a5 100644
> --- a/libavformat/ftp.c
> +++ b/libavformat/ftp.c
> @@ -183,6 +183,9 @@ static int ftp_send_command(FTPContext *s, const char *command,
> {
> int err;
>
> + if (response)
> + *response = NULL;
> +
> if ((err = ffurl_write(s->conn_control, command, strlen(command))) < 0)
> return err;
> if (!err)
> @@ -444,12 +447,14 @@ static int ftp_features(FTPContext *s)
> static const char *enable_utf8_command = "OPTS UTF8 ON\r\n";
> static const int feat_codes[] = {211, 0};
> static const int opts_codes[] = {200, 451};
> - char *feat;
> + char *feat = NULL;
>
> if (ftp_send_command(s, feat_command, feat_codes, &feat) == 211) {
> if (av_stristr(feat, "UTF8"))
> ftp_send_command(s, enable_utf8_command, opts_codes, NULL);
> }
> + av_freep(&feat);
> +
> return 0;
> }
>
> --
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140826/8b793670/attachment.asc>
More information about the ffmpeg-devel
mailing list