xfs
[Top] [All Lists]

Re: libattr - severe memory leaks from attr_copy_file()

To: Zdenek Prikryl <zprikryl@xxxxxxxxxx>
Subject: Re: libattr - severe memory leaks from attr_copy_file()
From: Eric Sandeen <sandeen@xxxxxxxxxxx>
Date: Thu, 19 Feb 2009 10:31:12 -0600
Cc: xfs@xxxxxxxxxxx
In-reply-to: <499D0471.6000600@xxxxxxxxxx>
References: <499D0471.6000600@xxxxxxxxxx>
User-agent: Thunderbird 2.0.0.19 (X11/20090105)
Zdenek Prikryl wrote:
>> And the variable, text, is assigned straight away before any use,
>> so I missed where the problem is.
>>
>> --Tim
> 
> The memory leak is really there. Look:
> 
> 54 attr_parse_attr_conf(struct error_context *ctx)
> ...
> 66 repeat:
> 67         text = malloc(size_guess + 1);
> 68         if (!text)
> 69                 goto fail;
> 70
> 71         if ((file = fopen(ATTR_CONF, "r")) == NULL) {
> 72                 if (errno == ENOENT)
> 73                         return 0;
> 74                 goto fail;
> 75         }
> 
> Let's say that malloc() on the line 67 success, so we have text != NULL. Then,
> fopen() on the line 71 fails and errno == ENOENT. In that case
> attr_parse_attr_conf() simply returns 0, but text isn't freed. That's the 
> point,
> where memory leaks arise. I rewrote the patch, so now is more simpler.

The patch you attached looks good to me, thanks.

-Eric

<Prev in Thread] Current Thread [Next in Thread>