From owner-freebsd-hackers@FreeBSD.ORG Mon Nov 16 20:32:07 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5FA36106566B for ; Mon, 16 Nov 2009 20:32:07 +0000 (UTC) (envelope-from volker@vwsoft.com) Received: from Mail.elbekies.net (mail.elbekies.net [217.6.211.146]) by mx1.freebsd.org (Postfix) with ESMTP id 1780C8FC1B for ; Mon, 16 Nov 2009 20:32:06 +0000 (UTC) Received: from mail.vtec.ipme.de (C4906.c.ppp-pool.de [62.104.73.6]) by Mail.elbekies.net (Postfix) with ESMTPA id 6312667885; Mon, 16 Nov 2009 21:13:04 +0100 (CET) Received: from [192.168.16.4] (dardanos.sz.vwsoft.com [192.168.16.4]) by mail.vtec.ipme.de (Postfix) with ESMTP id E127734278; Mon, 16 Nov 2009 21:12:48 +0100 (CET) Message-ID: <4B01B23F.8040002@vwsoft.com> Date: Mon, 16 Nov 2009 21:12:47 +0100 From: volker@vwsoft.com User-Agent: Thunderbird 2.0.0.23 (X11/20090902) MIME-Version: 1.0 To: Jim Wilcoxson References: In-Reply-To: X-Enigmail-Version: 0.95.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-VWSoft-MailScanner: Found to be clean X-MailScanner-ID: 6312667885.AA73E X-Elbekies-MailScanner: Found to be clean X-MailScanner-From: volker@vwsoft.com MailScanner-NULL-Check: 1259007193.09806@9YnDq+u+55Q3Uss2rwL9wA Cc: freebsd-hackers@freebsd.org Subject: Re: acl_from_text leaking memory X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Nov 2009 20:32:07 -0000 On 01/-10/63 20:59, 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 > #include > #include > > 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. > > Thanks, > Jim > -- > HashBackup beta: http://sites.google.com/site/hashbackup > Jim, you may want to have a look at the manpage acl_from_text(3): "...This function may cause memory to be allocated. The caller should free any releasable memory, when the new ACL is no longer required, by calling acl_free(3) with the (void *)acl_t as an argument." Please use an acl_free(void *obj_p) call afterwards to avoid leaking memory. Volker