You cannot run the shell command in . The code in the kernel module may cause the command to run, but it will work in a normal user process.
free will not help much with kernel memory leaks.
It would be much better to wrap all distributions and free the kernel in your code and save the allocated memory counter.
source share