Fixing memory leak caused by allocating empty array for parameters and not freeing it