fixed a memory leak in (de)compress_string

This commit is contained in:
Zeno Rogue 2022-08-07 01:57:06 +02:00
parent fba2cc95cf
commit 464f4277cc
3 changed files with 11 additions and 3 deletions

View File

@ -86,6 +86,11 @@ static const flagtype w_less_smart_retrace = Flag(22); /*< stop early when exami
static const flagtype w_less_smart_advance = Flag(23); /*< stop early when examining smart shortcut advancement */
static const flagtype w_no_queued_extensions = Flag(24); /*< consider extensions one by one */
static const flagtype w_no_branch_skipping = Flag(24); /*< do not skip branches */
/* for 3D honeycombs */
static const flagtype w_skip_transducers = Flag(32); /*< skip the transducer test */
static const flagtype w_skip_transducer_loops = Flag(33); /*< skip loops during the transducer test */
static const flagtype w_skip_transducer_terminate = Flag(34); /*< skip termination during the transducer test */
#endif
EX int honeycomb_value = 1; /* how far to build local for honeycombs */

View File

@ -1028,6 +1028,7 @@ EX void find_multiple_interpretation() {
}
EX void test_transducers() {
if(flags & w_skip_transducers) return;
autom.clear();
int iterations = 0;
while(true) {
@ -1159,7 +1160,7 @@ EX void test_transducers() {
extract(autom, special[tid][dir], tid, dir);
}
for(int tid=0; tid<isize(t_origin); tid++) {
if(!(flags & w_skip_transducer_loops)) for(int tid=0; tid<isize(t_origin); tid++) {
int id = 0;
/* if correct, each loop iteration recovers the identity, so we can build it just once */
@ -1189,7 +1190,7 @@ EX void test_transducers() {
}
}
if(true) {
if(!(flags & w_skip_transducer_terminate)) {
println(hlog, "Verifying distances");
map<pair<int, int>, vector< pair<int, int>> > by_roadsign;

View File

@ -737,6 +737,7 @@ EX string compress_string(string s) {
if(deflate(&strm, Z_FINISH) != Z_STREAM_END) throw hr_exception("z-error-2");
println(hlog, "deflate ok");
string out(&buf[0], (char*)(strm.next_out) - &buf[0]);
deflateEnd(&strm);
println(hlog, isize(s), " -> ", isize(out));
return out;
}
@ -753,8 +754,9 @@ EX string decompress_string(string s) {
vector<char> buf(10000000, 0);
strm.avail_out = 10000000;
strm.next_out = (Bytef*) &buf[0];
if(inflate(&strm, Z_FINISH) != Z_STREAM_END) throw hr_exception("z-error-2");
if(inflate(&strm, Z_FINISH) != Z_STREAM_END) throw hr_exception("z-error-2");
string out(&buf[0], (char*)(strm.next_out) - &buf[0]);
inflateEnd(&strm);
println(hlog, isize(s), " -> ", isize(out));
return out;
}