Skip to content

Commit 0b48fb8

Browse files
committed
Removing memory leaks.
1 parent a10e282 commit 0b48fb8

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ CFLAGS = -march=native -Idependencies/ujson4c/3rdparty -Idependencies/ujson4c/s
1212
ifeq ($(SANITIZE),1)
1313
CXXFLAGS += -g3 -O0 -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
1414
CFLAGS += -g3 -O0 -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
15+
else
16+
ifeq ($(DEBUG),1)
17+
CXXFLAGS += -g3 -O0
18+
CFLAGS += -g3 -O0
1519
else
1620
CXXFLAGS += -O3
1721
CFLAGS += -O3
1822
endif
23+
endif
1924

2025
MAINEXECUTABLES=parse minify json2json
2126
TESTEXECUTABLES=jsoncheck numberparsingcheck stringparsingcheck

benchmark/minifiercompetition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
7878
std::cout << p.size() << " B ";
7979
std::cout << std::endl;
8080
}
81-
char *buffer = allocate_aligned_buffer(p.size() + 1);
81+
char *buffer = allocate_padded_buffer(p.size() + 1);
8282
memcpy(buffer, p.data(), p.size());
8383
buffer[p.size()] = '\0';
8484

@@ -111,7 +111,7 @@ int main(int argc, char *argv[]) {
111111
BEST_TIME("RapidJSON Insitu orig", d.ParseInsitu(buffer).HasParseError(), false,
112112
memcpy(buffer, p.data(), p.size()), repeat, volume, true);
113113

114-
char *minibuffer = allocate_aligned_buffer(p.size() + 1);
114+
char *minibuffer = allocate_padded_buffer(p.size() + 1);
115115
size_t minisize = jsonminify((const uint8_t *)p.data(), p.size(), (uint8_t*) minibuffer);
116116
minibuffer[minisize] = '\0';
117117

tests/numberparsingcheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ bool validate(const char *dirname) {
154154
float_count, invalid_count,
155155
int_count + float_count + invalid_count);
156156
}
157-
free(p.data());
157+
free((void*)p.data());
158158
free(fullpath);
159159
}
160160
}

tools/json2json.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ int main(int argc, char *argv[]) {
8989
return EXIT_FAILURE;
9090
}
9191
bool is_ok = json_parse(p, pj); // do the parsing, return false on error
92+
free((void*)p.data());
9293
if (!is_ok) {
9394
std::cerr << " Parsing failed. " << std::endl;
9495
return EXIT_FAILURE;

tools/minify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ int main(int argc, char *argv[]) {
1818
}
1919
jsonminify(p, (char *)p.data());
2020
printf("%s",p.data());
21+
free((void*)p.data());
2122
}

0 commit comments

Comments
 (0)