Removing memory leaks.

This commit is contained in:
Daniel Lemire 2018-12-11 17:20:29 -05:00
parent a10e282eb4
commit 0b48fb8bd7
5 changed files with 10 additions and 3 deletions

View File

@ -12,10 +12,15 @@ CFLAGS = -march=native -Idependencies/ujson4c/3rdparty -Idependencies/ujson4c/s
ifeq ($(SANITIZE),1)
CXXFLAGS += -g3 -O0 -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
CFLAGS += -g3 -O0 -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
else
ifeq ($(DEBUG),1)
CXXFLAGS += -g3 -O0
CFLAGS += -g3 -O0
else
CXXFLAGS += -O3
CFLAGS += -O3
endif
endif
MAINEXECUTABLES=parse minify json2json
TESTEXECUTABLES=jsoncheck numberparsingcheck stringparsingcheck

View File

@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
std::cout << p.size() << " B ";
std::cout << std::endl;
}
char *buffer = allocate_aligned_buffer(p.size() + 1);
char *buffer = allocate_padded_buffer(p.size() + 1);
memcpy(buffer, p.data(), p.size());
buffer[p.size()] = '\0';
@ -111,7 +111,7 @@ int main(int argc, char *argv[]) {
BEST_TIME("RapidJSON Insitu orig", d.ParseInsitu(buffer).HasParseError(), false,
memcpy(buffer, p.data(), p.size()), repeat, volume, true);
char *minibuffer = allocate_aligned_buffer(p.size() + 1);
char *minibuffer = allocate_padded_buffer(p.size() + 1);
size_t minisize = jsonminify((const uint8_t *)p.data(), p.size(), (uint8_t*) minibuffer);
minibuffer[minisize] = '\0';

View File

@ -154,7 +154,7 @@ bool validate(const char *dirname) {
float_count, invalid_count,
int_count + float_count + invalid_count);
}
free(p.data());
free((void*)p.data());
free(fullpath);
}
}

View File

@ -89,6 +89,7 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
bool is_ok = json_parse(p, pj); // do the parsing, return false on error
free((void*)p.data());
if (!is_ok) {
std::cerr << " Parsing failed. " << std::endl;
return EXIT_FAILURE;

View File

@ -18,4 +18,5 @@ int main(int argc, char *argv[]) {
}
jsonminify(p, (char *)p.data());
printf("%s",p.data());
free((void*)p.data());
}