Skip to content

note.c: memory leak #236

Open
Open
@guijan

Description

@guijan

These lines of code leak:

scrot/src/note.c

Lines 122 to 123 in a1fbb65

case 'f':
note->font = parseText(&token, end);

parseText() allocates a string and returns it:
return strndup(begin, length);

If you pass a font file multiple times to the note feature, it will assign the return value of parseText() to note->font without free()ing note->font first. This leaks filenames as many times as font files are repeatedly specified.

I'd personally just remove the note feature entirely, but the fix is to make sure note->font is initialized to NULL and then free() it before calling parseText().

Edit: here's an example that leaks memory:

$ scrot -n "-f '/usr/share/fonts/TTF/DroidSans-Bold/40' -f '/usr/share/fonts/TTF/DroidSans-Bold/40' -x 10 -y 20 -c 255,0,0,255 -t 'Hi'"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions