Date: Mon, 16 Nov 2009 10:30:09 +0100 From: Christian Brueffer <brueffer@FreeBSD.org> To: Jim Wilcoxson <prirun@gmail.com> Cc: freebsd-bugs@freebsd.org, testing@lists.pcbsd.org Subject: Re: acl_from_text leaking memory Message-ID: <20091116093008.GB1459@serenity> In-Reply-To: <c5830b750911150804i694b00aai891819242816e89c@mail.gmail.com> References: <c5830b750911150804i694b00aai891819242816e89c@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On Sun, Nov 15, 2009 at 11:04:19AM -0500, Jim Wilcoxson wrote:
> I've been working on a new backup program, HashBackup, and believe I
> have found a memory leak with ACLs in PCBSD/FreeBSD 7.1 and OSX
> (Leopard).
>
> acl_from_text is a function that takes a text string as input, and
> returns a pointer to a malloc'd acl. This acl is then freed with
> acl_free. I noticed that acl_from_text appears to leak memory. This
> is not used during the backup of a filesystem, but is needed to do a
> restore.
>
> After looking at the acl_from_text source in /usr/src/lib/libc/posix1e
> (from PCBSD7.1), I believe the problem is that the duplicate text
> string, mybuf_p, is not freed on normal return of this function. Here
> is the end of this function:
>
> }
>
> #if 0
> /* XXX Should we only return ACLs valid according to acl_valid? */
> /* Verify validity of the ACL we read in. */
> if (acl_valid(acl) == -1) {
> errno = EINVAL;
> goto error_label;
> }
> #endif
>
> return(acl);
>
> error_label:
> acl_free(acl);
> free(mybuf_p);
> return(NULL);
> }
>
> I think there should be a free(mybuf_p) before return(acl).
>
> Here is a PCBSD/FreeBSD test program that causes the memory leak:
>
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/acl.h>
>
> main() {
> acl_t acl;
> char* acltext;
>
> acltext = "user::rw-\n group::r--\n mask::r--\n other::r--\n";
> while (1) {
> acl = acl_from_text(acltext);
> if (acl == NULL)
> printf("acl_from_text failed\n");
> if (acl_free(acl) != 0)
> printf("acl_free failed\n");
> }
> }
>
> I've subscribed to the lists for a few days in case there are
> questions or I can help test something.
>
Hi Jim,
this looks good, I`ve just committed it to HEAD. I will merge it to
the stable branches next week. Thanks for the submission!
- Christian
--
Christian Brueffer chris@unixpages.org brueffer@FreeBSD.org
GPG Key: http://people.freebsd.org/~brueffer/brueffer.key.asc
GPG Fingerprint: A5C8 2099 19FF AACA F41B B29B 6C76 178C A0ED 982D
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (FreeBSD)
iEYEARECAAYFAksBG6AACgkQbHYXjKDtmC2nIgCfbL2meL4DiA1moZl9f5cnL8VZ
zasAoKngKM/90ry+MoyooNAPJeRhHMtY
=10U9
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20091116093008.GB1459>
