zserge / partcl

ParTcl - a micro Tcl implementation
https://zserge.com/posts/tcl-interpreter/
MIT License
470 stars 50 forks source link

added custom malloc implementation #5

Open Igor1101 opened 6 years ago

Igor1101 commented 6 years ago

I would like to use your partcl in my embedded projects so I have written malloc for this program in order to remove more dependencies and run it on bare metal. But I found out that your program does not always use free() correctly. Sometimes it does not use correct pointer to allocated memory when uses "subst". Furthermore I could not find where your fault really is. My implementation of free() named "sfree()" prints "free called" when it is really called and prints "FREE ERROR", when it cannot recognize what is the pointer it received. Just type "make|less" to see this. Maybe you can find this mistake? There is also another problem: partcl does not verify if malloc returns NULL pointer. Maybe it is a good idea to run "exit(1);" from custom malloc/realloc instead of returning NULL.

whiterocker commented 6 years ago

Hi Igor, at least one memory leak is because at line 331, in tcl_eval( ), the function returns without freeing the variable list. Need to add tcl_list_free(list) before the return.

skrasser commented 3 years ago

@Igor1101, there is a free() on non-heap memory in the tests for subst, so you may have seen that when running make|less. It only impacts the tests. See here: https://github.com/zserge/partcl/pull/12.