misc/161425: Memory leak in localtime.c's tzload()

Fabian Keil fk at fabiankeil.de
Sun Oct 9 15:00:23 UTC 2011


>Number:         161425
>Category:       misc
>Synopsis:       Memory leak in localtime.c's tzload()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Oct 09 15:00:22 UTC 2011
>Closed-Date:
>Last-Modified:
>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 at 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:
>Unformatted:


More information about the freebsd-bugs mailing list