base_folder parameter should be copied with strdup in hoedown_document_new()
fabiocolacio opened this issue · comments
Fábio Colácio commented
I kept running into a double-free error when using Scidown, because apparently the hoedown_document_new
does not copy the entire base_folder
string, but instead copies the pointer.
This leads to undefined behaviour, because:
- If I change the contents of the
base_folder
string after callinghoedown_document_new ()
, Scidown will no longer have the correct directory. - If Scidown frees or modify the string when I still need it, my code will act in an undefined way.
This is the problematic line:
Line 3309 in 14a78de
I would suggest changing it to doc->base_folder = strdup (base_folder)
Also, I would suggest changing the base_folder
parameter to be const char*
to prevent the string from being corrupted (or at least throw a warning at compile-time).