diff --git a/src/LASlib/lasdefinitions.hpp b/src/LASlib/lasdefinitions.hpp index ec92dd6..32a5ed6 100644 --- a/src/LASlib/lasdefinitions.hpp +++ b/src/LASlib/lasdefinitions.hpp @@ -756,12 +756,18 @@ class LASheader : public LASquantizer, public LASattributer if (delete_data) { delete [] evlrs[i].data; + evlrs[i].data = 0; } } number_of_extended_variable_length_records--; if (number_of_extended_variable_length_records) { - evlrs[i] = evlrs[number_of_extended_variable_length_records]; + // Fix for #67. I do not understand why realloc corrupts the memory. + LASevlr* tmp = (LASevlr*)calloc(number_of_extended_variable_length_records, sizeof(LASevlr)); + for (U32 j = 0, k = 0; j < number_of_extended_variable_length_records+1; ++j) { if (j != i) { tmp[k++] = evlrs[j]; }} + free(evlrs); + evlrs = tmp; + //evlrs[i] = evlrs[number_of_extended_variable_length_records]; //evlrs = (LASevlr*)realloc(evlrs, sizeof(LASvlr)*number_of_extended_variable_length_records); } else