Bug 161425 - [libc] Memory leak in localtime.c's tzload()
Summary: [libc] Memory leak in localtime.c's tzload()
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
Depends on:
Reported: 2011-10-09 16:00 UTC by Fabian Keil
Modified: 2011-10-30 09:31 UTC (History)
0 users

See Also:

file.txt (726 bytes, text/plain)
2011-10-09 16:00 UTC, Fabian Keil
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fabian Keil 2011-10-09 16:00:22 UTC
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)

Fix: The attached patch seems to fix it for me.

Patch attached with submission follows:
How-To-Repeat: Use valgrind with an application that uses (for example) localtime_r().
Comment 1 Mikolaj Golub freebsd_committer 2011-10-30 08:18:59 UTC
State Changed
From-To: open->patched

Fixed in HEAD.
Comment 2 dfilter service freebsd_committer 2011-10-30 08:35:33 UTC
Author: trociny
Date: Sun Oct 30 08:35:19 2011
New Revision: 226929
URL: http://svn.freebsd.org/changeset/base/226929

  MFC r226828:
  Fix a memory leak in tzload().
  PR:		bin/161425
  Reviewed by:	kib
  Approved by:	re (kib)

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;
 			return -1;
+		free(fullname);
 	u = malloc(sizeof(*u));
 	if (u == NULL)
svn-src-all@freebsd.org mailing list
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 3 Mikolaj Golub freebsd_committer 2011-10-30 09:29:50 UTC
State Changed
From-To: patched->closed

Fixed in stable/9.