Skip to content

Memory leaks when using printf date/time formatting with user supplied date/time #995

@tiny28

Description

@tiny28

The following loop that makes use of the shell's builtin printf date/time formatting causes a slow memory leak.
The offending bit seems to be the second printf statement which parses a user specified date/time

while sleep 0.01s; do
printf -v date '%(%K.%3N)T'
printf -v jday '%(%j)T' "${date}"
done

Showing memory growth over time. $PID is set to the pid of the backgrounded script containing the loop.

while kill -0 $PID 2>/dev/null; do
ps -p $PID -o pid,vsz,rss,comm --no-headers
sleep 1
done

6746 9120 4896 testscript
6746 9120 4924 testscript
6746 9120 4948 testscript
6746 9120 4976 testscript
6746 9252 5000 testscript
6746 9252 5024 testscript
6746 9252 5052 testscript
6746 9252 5076 testscript
6746 9252 5104 testscript
6746 9384 5128 testscript
6746 9384 5156 testscript
6746 9384 5180 testscript
6746 9384 5208 testscript
6746 9384 5232 testscript
6746 9516 5260 testscript
6746 9516 5284 testscript
6746 9516 5312 testscript
6746 9516 5336 testscript
6746 9516 5364 testscript
6746 9516 5388 testscript
6746 9648 5416 testscript
6746 9648 5440 testscript

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions