Commit title: Correct some leaks of memory

Description:
    - correct some leaks of memory in several files

Comment:
    - They still are a few in add_element, but I think it's a valgrind
      false positive because I free them but later