NetBSD-Bugs archive

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

lib/57699: Memory leak in libprop?



>Number:         57699
>Category:       lib
>Synopsis:       Memory leak in libprop?
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 17 09:45:00 +0000 2023
>Originator:     M. Boerschig
>Release:        10.0_RC1
>Organization:
>Environment:
NetBSD mybox 10.0_RC1 NetBSD 10.0_RC1 (GENERIC) #0: Sun Nov  5 18:30:08 UTC 2023  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64

>Description:
I noticed a memory leak while writing a widget for monitoring my laptop battery using envsys.
I boiled it down to libprop, see the reproducer listed below.
First thought was I didn't use libprop properly, but adress sanitizer complains, too.

Also: `envstat -i 1` leaks slowly memory -- the resident memory grows continuously when watched using `top` (might take a couple of hours).


>How-To-Repeat:
The following program will report an adress sanitizer leak:

// compile: gcc -O0 -o libprop_leak libprop_leak.c -lprop -fsanitize=address 
#include <sys/envsys.h>
#include <prop/proplib.h>
#include <paths.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

int main() {
    //while(1) {
    prop_dictionary_t dict;
    int result = 0;
    int sysmonfd = -1;
    if ((sysmonfd = open(_PATH_SYSMON, O_RDONLY)) == -1) {
        return -1;
    }
    result = prop_dictionary_recv_ioctl(sysmonfd, ENVSYS_GETDICTIONARY, &dict);
    if(result == -1) {
        return -2;
    }
    prop_object_release(dict);
    (void)close(sysmonfd);
   // }
}

Will result in the following sanitizer output:

=================================================================
==22658==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 194 byte(s) in 25 object(s) allocated from:
    #0 0x7f7ff6e435ff in malloc (/usr/lib/libasan.so.5+0x435ff)
    #1 0x7f7ff6a092d6 in _prop_string_internalize (/usr/lib/libprop.so.1+0x92d6)
    #2 0x7f7ff6a09cc6 in _prop_object_internalize_by_tag (/usr/lib/libprop.so.1+0x9cc6)
    #3 0x7f7ff6a0a612 in _prop_generic_internalize (/usr/lib/libprop.so.1+0xa612)
    #4 0x7f7ff6a06f92 in prop_dictionary_recv_ioctl (/usr/lib/libprop.so.1+0x6f92)
    #5 0x400dc8 in main (/build/mb/battery/./libprop_leak+0x400dc8)
    #6 0x400c6c in ___start /usr/src/lib/csu/common/crt0-common.c:350:2
    #7 0x7f7ff7c0baf7  (/usr/libexec/ld.elf_so+0xbaf7)

SUMMARY: AddressSanitizer: 194 byte(s) leaked in 25 allocation(s).
>Fix:



Home | Main Index | Thread Index | Old Index