libattr - severe memory leaks from attr_copy_file()

Zdenek Prikryl zprikryl at redhat.com
Thu Feb 19 01:04:17 CST 2009


> 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.

-- 
Zdenek Prikryl <zprikryl at redhat.com>

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: attr-2.4.43-leak.patch
URL: <http://oss.sgi.com/pipermail/xfs/attachments/20090219/458e79e8/attachment.bat>


More information about the xfs mailing list