Skip to content

Commit e8d3d78

Browse files
committed
More fixing.
1 parent 058eb91 commit e8d3d78

File tree

9 files changed

+14
-5
lines changed

9 files changed

+14
-5
lines changed

benchmark/minifiercompetition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ int main(int argc, char *argv[]) {
143143
}
144144

145145
BEST_TIME("json_parse despaced", json_parse((const u8*)buffer, minisize, pj2), true, memcpy(buffer, minibuffer, p.size()), repeat, volume, true);
146-
146+
free((void*)p.data());
147147
free(buffer);
148148
free(ast_buffer);
149149
free(minibuffer);

benchmark/parse.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ int main(int argc, char *argv[]) {
229229
if(dump) {
230230
isok = isok && pj.dump_raw_tape(std::cout);
231231
}
232+
free((void*)p.data());
232233
if (!isok) {
233234
printf(" Parsing failed. \n ");
234235
return EXIT_FAILURE;

benchmark/parsingcompetition.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ int main(int argc, char *argv[]) {
121121
void *state;
122122
if(all) BEST_TIME("ultrajson ", (UJDecode(buffer, p.size(), NULL, &state) == NULL), false, memcpy(buffer, p.data(), p.size()), repeat, volume, true);
123123
BEST_TIME("memcpy ", (memcpy(buffer, p.data(), p.size()) == buffer), true, , repeat, volume, true);
124+
free((void*)p.data());
124125
free(ast_buffer);
125126
free(buffer);
126127
}

include/simdjson/jsonioutil.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ char * allocate_padded_buffer(size_t length);
2626
// throws exceptions in case of failure
2727
// first element of the pair is a string (null terminated)
2828
// whereas the second element is the length.
29-
// caller is responsible to free (free std::pair<u8 *, size_t>.first)
29+
// caller is responsible to free (free((void*)result.data())))
3030
//
3131
// throws an exception if the file cannot be opened, use try/catch
3232
// try {
3333
// p = get_corpus(filename);
3434
// } catch (const std::exception& e) {
35+
// free((void*)p.data());
3536
// std::cout << "Could not load the file " << filename << std::endl;
3637
// }
3738
std::string_view get_corpus(std::string filename);

src/jsonioutil.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ std::string_view get_corpus(std::string filename) {
2525
throw std::runtime_error("could not allocate memory");
2626
}
2727
std::rewind(fp);
28-
std::fread(buf, 1, len, fp);
29-
//buf[len] = '\0';// no need
28+
size_t readb = std::fread(buf, 1, len, fp);
3029
std::fclose(fp);
30+
if(readb != len) {
31+
free(buf);
32+
throw std::runtime_error("could not read the data");
33+
}
3134
return std::string_view(buf,len);
3235
}
3336
throw std::runtime_error("could not load corpus");

tests/allparserscheckfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int main(int argc, char *argv[]) {
108108
printf("fastjson : %s \n", fastjson_correct ? "correct":"invalid");
109109
printf("gason : %s \n", gason_correct ? "correct":"invalid");
110110
printf("ultrajson : %s \n", ultrajson_correct ? "correct":"invalid");
111-
111+
free((void*)p.data());
112112
free(buffer);
113113
return EXIT_SUCCESS;
114114
}

tests/jsoncheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ bool validate(const char *dirname) {
7575
}
7676
++howmany;
7777
bool isok = json_parse(p, pj);
78+
free((void*)p.data());
7879
printf("%s\n", isok ? "ok" : "invalid");
7980
if(contains("EXCLUDE",name)) {
8081
// skipping

tests/numberparsingcheck.cpp

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

tests/stringparsingcheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ bool validate(const char *dirname) {
343343
total_string_length = 0;
344344
empty_string = 0;
345345
bool isok = json_parse(p, pj);
346+
free((void*)p.data());
346347
if (good_string > 0) {
347348
printf("File %40s %s --- bad strings: %10zu \tgood strings: %10zu\t "
348349
"empty strings: %10zu "

0 commit comments

Comments
 (0)