From nobody@FreeBSD.org  Sun Oct  9 14:50:45 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 412C11065670
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  9 Oct 2011 14:50:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 30F4B8FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  9 Oct 2011 14:50:45 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p99EoiYA033444
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 9 Oct 2011 14:50:44 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p99EoiHW033443;
	Sun, 9 Oct 2011 14:50:44 GMT
	(envelope-from nobody)
Message-Id: <201110091450.p99EoiHW033443@red.freebsd.org>
Date: Sun, 9 Oct 2011 14:50:44 GMT
From: Fabian Keil <fk@fabiankeil.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Memory leak in localtime.c's tzload()
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         161425
>Category:       bin
>Synopsis:       [libc] Memory leak in localtime.c's tzload()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Oct 09 15:00:22 UTC 2011
>Closed-Date:    Sun Oct 30 09:31:10 UTC 2011
>Last-Modified:  Sun Oct 30 09:31:10 UTC 2011
>Originator:     Fabian Keil
>Release:        HEAD
>Organization:
>Environment:
>Description:
r225677 seems to have introduced a memory leak:

==6439== 1,025 bytes in 1 blocks are definitely lost in loss record 95 of 132
==6439==    at 0x105E47B: malloc (vg_replace_malloc.c:236)
==6439==    by 0x1BCEA42: ??? (localtime.c:414)
==6439==    by 0x1BCF41A: ??? (localtime.c:1253)
==6439==    by 0x1BCF7F3: localtime_r (localtime.c:1482)
==6439==    by 0x41F9F7: get_log_timestamp (errlog.c:454)
==6439==    by 0x41FF90: log_error (errlog.c:690)
==6439==    by 0x41F646: show_version (errlog.c:199)
==6439==    by 0x42D204: main (jcc.c:3036)

>How-To-Repeat:
Use valgrind with an application that uses (for example) localtime_r().
>Fix:
The attached patch seems to fix it for me.

Patch attached with submission follows:

From 2e481a94e78d21c75f43706f637660fe0a7c3ab7 Mon Sep 17 00:00:00 2001
From: Fabian Keil <fk@fabiankeil.de>
Date: Sat, 8 Oct 2011 20:28:16 +0200
Subject: [PATCH] Fix a memory leak in tzload()

---
 contrib/tzcode/stdtime/localtime.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/contrib/tzcode/stdtime/localtime.c b/contrib/tzcode/stdtime/localtime.c
index d9544a9..a59bb1d 100644
--- a/contrib/tzcode/stdtime/localtime.c
+++ b/contrib/tzcode/stdtime/localtime.c
@@ -445,8 +445,8 @@ register const int	doextend;
 			free(fullname);
 			return -1;
 		}
+		free(fullname);
 		if ((_fstat(fid, &stab) < 0) || !S_ISREG(stab.st_mode)) {
-			free(fullname);
 			_close(fid);
 			return -1;
 		}
-- 
1.7.6



>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: trociny 
State-Changed-When: Sun Oct 30 08:18:59 UTC 2011 
State-Changed-Why:  
Fixed in HEAD. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=161425 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/161425: commit references a PR
Date: Sun, 30 Oct 2011 08:35:33 +0000 (UTC)

 Author: trociny
 Date: Sun Oct 30 08:35:19 2011
 New Revision: 226929
 URL: http://svn.freebsd.org/changeset/base/226929
 
 Log:
   MFC r226828:
   
   Fix a memory leak in tzload().
   
   PR:		bin/161425
   Reviewed by:	kib
   Approved by:	re (kib)
 
 Modified:
   stable/9/contrib/tzcode/stdtime/localtime.c
 Directory Properties:
   stable/9/contrib/tzcode/   (props changed)
   stable/9/contrib/tzcode/stdtime/   (props changed)
   stable/9/contrib/tzcode/zic/   (props changed)
 
 Modified: stable/9/contrib/tzcode/stdtime/localtime.c
 ==============================================================================
 --- stable/9/contrib/tzcode/stdtime/localtime.c	Sun Oct 30 05:06:14 2011	(r226928)
 +++ stable/9/contrib/tzcode/stdtime/localtime.c	Sun Oct 30 08:35:19 2011	(r226929)
 @@ -450,6 +450,7 @@ register const int	doextend;
  			_close(fid);
  			return -1;
  		}
 +		free(fullname);
  	}
  	u = malloc(sizeof(*u));
  	if (u == NULL)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: trociny 
State-Changed-When: Sun Oct 30 09:29:50 UTC 2011 
State-Changed-Why:  
Fixed in stable/9. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=161425 
>Unformatted:
