Martinsos / edlib

Lightweight, super fast C/C++ (& Python) library for sequence alignment using edit (Levenshtein) distance.
http://martinsos.github.io/edlib
MIT License
514 stars 167 forks source link

Mismatched free() / delete[] #59

Closed isovic closed 7 years ago

isovic commented 7 years ago

Hi Martin, here is a bit I found when profiling:
Memory for positions here is allocated using malloc:
https://github.com/Martinsos/edlib/blob/master/edlib/src/edlib.cpp#L550 But freed here using delete[]:
https://github.com/Martinsos/edlib/blob/master/edlib/src/edlib.cpp#L179

Best regards, Ivan.

isovic commented 7 years ago

Also, what happens here if numPositionsSHW here is <=0?
https://github.com/Martinsos/edlib/blob/master/edlib/src/edlib.cpp#L178

Ivan

Martinsos commented 7 years ago

Thanks, good find! How did you do the profiling, with which tool? I fixed the problem with c19a0754aec29a88e01ab76c3a1357eaa9f1f10e, and added better documentation for internal functions. Nothing happens if it is <= 0 since its initial value is never used, it is used only to return the number of positions that were found.

isovic commented 7 years ago

Np. Just Valgrind actually :-) valgrind --tool=memcheck --leak-check=full

Martinsos commented 7 years ago

Great - I added checking for memory leaks to Travis with 75c50ceffdeef1fb6c582fa94eaae9919ab85510, so now I will be sure that all is fine.

isovic commented 7 years ago

Awesome, I didn't know about --error-exitcode. I will use it in the future :-)