NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/45627: unclear memory leaks

>Number:         45627
>Category:       lib
>Synopsis:       unclear memory leaks
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Nov 17 21:15:00 +0000 2011
>Originator:     Martin Husemann
>Release:        NetBSD 5.99.56
The NetBSD Foundation, Inc.
System: NetBSD 5.99.56 NetBSD 5.99.56 (MP3) #41: Thu Nov 17 
20:22:24 CET 2011 
Architecture: sparc
Machine: sparc

The below test program (intended to test for something else originally)
prints random 64bit numbers in an endless loop. It uses no dynamic
allocations once it enters the loop, nevertheless the program increases
its memory size constantly (and pretty fast). On a sparc with typical
memory  configurations it gets killed after an hour or so.


cc -O2 -Wall -o t_snprintf t_snprintf.c && ./t_snprintf

with t_snptrinf.c being:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <time.h>

int main(int argc, char **argv)
        union {
                double d;
                uint64_t bits;
        } u;
        uint32_t ul, uh;
        time_t now;
        char buf[1000];

        for (;;) {
                ul = rand();
                uh = rand();
                u.bits = (uint64_t)uh << 32 | ul;

                printf("\r%08" PRIx64 "  ", u.bits); fflush(stdout);
                snprintf(buf, sizeof buf, " %.2f", u.d);
//              printf("as double: %s\n\n", buf);

        return 0;


Home | Main Index | Thread Index | Old Index