Fixing the memory leaks in gillespieMeanOnGrid and gillespieMeanSDOnGrid