shc icon indicating copy to clipboard operation
shc copied to clipboard

Fix memory leaks in write_c and eval_shell

Open ashamedbit opened this issue 1 year ago • 1 comments

Hi, I am a new contributor looking forward to contribute to the shc project :). I came across the following open issue here #155 It is a leaksanitizer report which detects a leak that happens on passing a simple bash script. I was able to reproduce the bug on running a custom shell script and was able to generate a patch for it. The leak happens within function write_c. Basically all the allocated variables in this function including msg1, msg2, chk1, chk2, tst1, tst2 and name need to be freed after allocation. I have a model patch and I was wondering if I can merge the same.

I was able to verify that after the patch, the leak no longer occurs through leaksanitizer (and there is no double free for that matter)

In addition I have also patched a leak that I encountered when running on an invalid bash script. This new leak happens in eval_shell function when an invalid first line on script is encountered. Here ptr is allocated but not freed before the abrupt exit.

Let me know if this is a good patch! If not let me know what changes need be done. I am eager to become a regular contributor to this repository :)

ashamedbit avatar Jan 28 '24 23:01 ashamedbit

LGTM, @neurobin?

suntong avatar Aug 10 '24 13:08 suntong