Skip to content

memleak in mnt_table_parse_swaps() #596

@keszybz

Description

@keszybz

Hi,

I was writing a unittest for systemd, and found what seems to be a small memleak in mnt_table_parse_swaps(). I'm parsing the following dummy file:

Filename				Type		Size	Used	Priority
/dev/dm-2                               partition	8151036	2283436	-2
/some/swapfile                          file            111     111     0
/some/swapfile2 (deleted)               file            111     111     0

and get the following report from valgrind:

    ==26912== 16 bytes in 1 blocks are definitely lost in loss record 1 of 1
    ==26912==    at 0x4C31C15: realloc (vg_replace_malloc.c:785)
    ==26912==    by 0x55C5D8C: _IO_vfscanf (in /usr/lib64/libc-2.26.so)
    ==26912==    by 0x55D8AEC: vsscanf (in /usr/lib64/libc-2.26.so)
    ==26912==    by 0x55D25C3: sscanf (in /usr/lib64/libc-2.26.so)
    ==26912==    by 0x53236D0: mnt_table_parse_stream (in /usr/lib64/libmount.so.1.1.0)
    ==26912==    by 0x53249B6: mnt_table_parse_file (in /usr/lib64/libmount.so.1.1.0)
    ==26912==    by 0x10D157: swap_list_get (umount.c:194)
    ==26912==    by 0x10B06E: test_swap_list (test-umount.c:34)
    ==26912==    by 0x10B24B: main (test-umount.c:56)

The memleaks comes from the line with " (deleted)". If I duplicate that line, valgrind reports a lost block for each copy.

I'll push my PR to systemd shortly, so a reference to it should pop up here in case you want to see the code.

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