Skip to content

Fix small memory leak of 40 bytes in sh_main() - #1032

Open
JohnoKing wants to merge 1 commit into
ksh93:devfrom
JohnoKing:small-leak
Open

JohnoKing wants to merge 1 commit into
ksh93:devfrom
JohnoKing:small-leak

Conversation

@JohnoKing

Copy link
Copy Markdown

Minimal reproducer for the memory leak:

$ arch/*/bin/ksh true
true: true: cannot execute [Exec format error]

=================================================================
==458768==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f7bd5360181 in malloc (/usr/lib/libasan.so.8+0x160181) (BuildId: 5f5511943a2d1bbff3f628464c43ad8c6ed91d5b)
    #1 0x562dc27e013d in sh_malloc /home/johno/GitRepos/KornShell/ksh/src/cmd/ksh93/sh/init.c:234
    #2 0x562dc2a08033 in path_fullname /home/johno/GitRepos/KornShell/ksh/src/cmd/ksh93/sh/path.c:526
    #3 0x562dc273ae45 in sh_main /home/johno/GitRepos/KornShell/ksh/src/cmd/ksh93/sh/main.c:246
    #4 0x562dc27385a2 in main /home/johno/GitRepos/KornShell/ksh/src/cmd/ksh93/sh/pmain.c:41
    #5 0x7f7bd4627d0d  (/usr/lib/libc.so.6+0x27d0d) (BuildId: 5e3b85a3eaa72d02eaae3882b22410ebda6b5555)
    #6 0x7ffc5d4ab4e1  (<unknown module>)

src/cmd/ksh93/sh/init.c:

  • Free sh.st.filename before allocation if memory was already allocated to it during shell initialization.

Minimal reproducer for the memory leak:

$ arch/*/bin/ksh true
   true: true: cannot execute [Exec format error]

   =================================================================
   ==458768==ERROR: LeakSanitizer: detected memory leaks

   Direct leak of 40 byte(s) in 1 object(s) allocated from:
     #0 0x7f7bd5360181 in malloc (/usr/lib/libasan.so.8+0x160181) (BuildId: 5f5511943a2d1bbff3f628464c43ad8c6ed91d5b)
     ksh93#1 0x562dc27e013d in sh_malloc /home/johno/GitRepos/KornShell/ksh/src/cmd/ksh93/sh/init.c:234
     ksh93#2 0x562dc2a08033 in path_fullname /home/johno/GitRepos/KornShell/ksh/src/cmd/ksh93/sh/path.c:526
     ksh93#3 0x562dc273ae45 in sh_main /home/johno/GitRepos/KornShell/ksh/src/cmd/ksh93/sh/main.c:246
     ksh93#4 0x562dc27385a2 in main /home/johno/GitRepos/KornShell/ksh/src/cmd/ksh93/sh/pmain.c:41
     ksh93#5 0x7f7bd4627d0d  (/usr/lib/libc.so.6+0x27d0d) (BuildId: 5e3b85a3eaa72d02eaae3882b22410ebda6b5555)
     ksh93#6 0x7ffc5d4ab4e1  (<unknown module>)

src/cmd/ksh93/sh/init.c:
- Free sh.st.filename if memory was already allocated to it
  during shell initialization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant