From patchwork Tue Jul 8 17:45:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 367978 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 8FC7D140095 for ; Wed, 9 Jul 2014 03:46:06 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=fbIX RlgKXk60JEgYbk/qiNxmVY/JMv1hhyFNnFavu3a/cONLxVTxGVTCMP2TE5ivvYFL 5BjQTRFZlsuxI7j0A4mOeA1m4yOY72AD5OerYYiAus9mxov5bEkF/gJUK35wFSjp KfkRvvTkwE5s1IjRj7GrRsmllFoEprwnNfbYDX8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=nA3aCzmfb2 vVaF/8lUH2OvsKrCw=; b=sDZwwBbOHN3ZM6NADyYROgyKzAk3wc7S1f0NBxMHBF dQy+2wjUB6InZNlaF83snaLlWk62UekJ7WPsUz1cdkoH50o8lAnku6LKhjVkSmZ6 nDs0+htJAPqYcdU8mtd1P47guWBFRrRx5wqN66O3MRP+0NXx3mnm9/jDgxsxKGNq E= Received: (qmail 17343 invoked by alias); 8 Jul 2014 17:45:46 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 17300 invoked by uid 89); 8 Jul 2014 17:45:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Date: Tue, 8 Jul 2014 23:15:33 +0530 From: Siddhesh Poyarekar To: Andreas Schwab Cc: libc-alpha@sourceware.org Subject: [PATCH v2] Fix crash when system has no ipv6 address [BZ #17125] Message-ID: <20140708174533.GK609@spoyarek.pnq.redhat.com> References: <20140708120846.GH609@spoyarek.pnq.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.22.1-rc1 (2013-10-16) Hi, Here's an updated patch to fix the crash in bug-ga2 when the system has no configured ipv6 address. I have taken a different approach of using libc_freeres_fn instead of the libc_freeres_ptr since the former gives better control over what is freed; we need that since cache may or may not be allocated using malloc. Verified that bug-ga2 works correctly in both cases and does not have memory leaks in either of them. Siddhesh [BZ #17125] * sysdeps/unix/sysv/linux/check_pf.c (cache): Don't use libc_freeres_ptr. (freecache): New function to free CACHE on exit. diff --git a/sysdeps/unix/sysv/linux/check_pf.c b/sysdeps/unix/sysv/linux/check_pf.c index 1bc1def..c7fd9b0 100644 --- a/sysdeps/unix/sysv/linux/check_pf.c +++ b/sysdeps/unix/sysv/linux/check_pf.c @@ -61,7 +61,7 @@ static struct cached_data noai6ai_cached = .in6ailen = 0 }; -libc_freeres_ptr (static struct cached_data *cache); +static struct cached_data *cache; __libc_lock_define_initialized (static, lock); @@ -401,6 +401,12 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6, *seen_ipv6 = true; } +/* Free the cache if it has been allocated. */ +libc_freeres_fn (freecache) +{ + if (cache) + __free_in6ai (cache->in6ai); +} void __free_in6ai (struct in6addrinfo *ai)