I think I found it, was a memory corruption in another module of the application, when I fixed it everything worked perfectly and valgrind won't show any errors. Bye