NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/50259: Small memory leaks in localtime's code
>Number: 50259
>Category: lib
>Synopsis: Small memory leaks in localtime's code
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Sep 19 12:50:00 +0000 2015
>Originator: David CARLIER
>Release: current
>Organization:
>Environment:
NetBSD 7.99.21 NetBSD 7.99.21 (GENERIC) #0: Sat Sep 19 08:11:51 IST 2015 root@:/usr/obj/sys/arch/amd64/compile/GENERIC amd64
>Description:
Hi all,
localtime uses two internal static states variables which are allocated once. But, they re never freed. This patch suppresses the need of dynamic memory allocation.
Hope it helps.
>How-To-Repeat:
>Fix:
Index: time/localtime.c
===================================================================
RCS file: /cvsroot/src/lib/libc/time/localtime.c,v
retrieving revision 1.97
diff -r1.97 localtime.c
170,171c170,173
< static timezone_t lclptr;
< static timezone_t gmtptr;
---
> static struct state lclmem;
> static struct state gmtmem;
> static timezone_t lclptr = &lclmem;
> static timezone_t gmtptr = &gmtmem;
1295,1302c1297,1300
< if (! sp)
< lclptr = sp = malloc(sizeof *lclptr);
< if (sp) {
< if (zoneinit(sp, name) != 0)
< zoneinit(sp, "");
< if (0 < lcl)
< strcpy(lcl_TZname, name);
< }
---
> if (zoneinit(sp, name) != 0)
> zoneinit(sp, "");
> if (0 < lcl)
> strcpy(lcl_TZname, name);
1337,1339c1335
< gmtptr = malloc(sizeof *gmtptr);
< if (gmtptr)
< gmtload(gmtptr);
---
> gmtload(gmtptr);
1529,1530c1525
< result->TM_ZONE = offset ? __UNCONST(wildabbr) : gmtptr ?
< gmtptr->chars : __UNCONST(gmt);
---
> result->TM_ZONE = offset ? __UNCONST(wildabbr) : gmtptr->chars;
2281,2282c2276
< if (lclptr)
< t = (time_t)(t - leapcorr(lclptr, t));
---
> t = (time_t)(t - leapcorr(lclptr, t));
2323,2324c2317
< if (lclptr)
< t = posix2time_z(lclptr, t);
---
> t = posix2time_z(lclptr, t);
Home |
Main Index |
Thread Index |
Old Index