Skip to content

Memory leak in mdadm --monitor --scan #195

@yxist

Description

@yxist

Hello,
We reported this bug to https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1115497
We were asked to repost it here.

We noticed a memory leak in mdadm --monitor --scan on all of our newly installed Debian 13 machines.
The worst case machine accumulated about 20GB of leaks in 13 days of uptime.

After some debugging we found the issue.
At udev.c:151 in the udev_wait_for_events function:

if (udev_monitor_receive_device(udev_monitor))
	return UDEV_STATUS_SUCCESS; /* event detected */

According to libudev docs:

On success, udev_monitor_receive_device() returns a pointer to a newly referenced device that was received via the monitor. The caller is responsible to drop this reference when done.

As you can see, the reference to the device never gets dropped.
We put together a quick patch, which seems to have fixed the issue or at least substantially reduced the amount of leaks.
memory_leak_fix.patch
We are unfamiliar with the codebase, feel free to reformat/rewrite appropriately.

Additionally for anyone with the same issue, passing MDADM_NO_UDEV=1 env to mdadm stops the leaks as well, since it bypasses the leaking codepath.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions