avahi icon indicating copy to clipboard operation
avahi copied to clipboard

There is a memory leak in avahi_init_proc_title

Open evverx opened this issue 1 month ago • 2 comments

+ valgrind --leak-check=full --track-origins=yes --track-fds=yes --exit-on-first-error=yes --error-exitcode=1 avahi-daemon -h
...
==53947== 
==53947== FILE DESCRIPTORS: 3 open (3 std) at exit.
==53947== 
==53947== HEAP SUMMARY:
==53947==     in use at exit: 5,716 bytes in 129 blocks
==53947==   total heap usage: 132 allocs, 3 frees, 9,862 bytes allocated
==53947== 
==53947== 5,716 (1,032 direct, 4,684 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 2
==53947==    at 0x4846828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==53947==    by 0x486AE00: xmalloc (malloc.c:68)
==53947==    by 0x486AEF5: avahi_malloc (malloc.c:107)
==53947==    by 0x119E5C: avahi_init_proc_title (setproctitle.c:68)
==53947==    by 0x113BA3: main (main.c:1575)
==53947== 
==53947== 
==53947== Exit program on first error (--exit-on-first-error=yes)

evverx avatar Nov 15 '25 16:11 evverx

Systemd code has a function named rename_process, which seemingly does the better job. Not sure if it is possible to reuse it in Avahi, though.

arrowd avatar Nov 29 '25 16:11 arrowd

The systemd codebase is really different from avahi in that it comes with, say, cleanup attributes that help with all sorts of leaks tremendously so it can't be easily adopted here. Some ideas can be borrowed of course if it makes sense. Other than that in this particular case when avahi-daemon -h is run it shouldn't even try to change the proc title or anything else really.

evverx avatar Nov 30 '25 18:11 evverx