1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-10-31 19:36:16 +00:00

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_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_queued_extensions = Flag(24); /*< consider extensions one by one */
static const flagtype w_no_branch_skipping = Flag(24); /*< do not skip branches */ 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 #endif
EX int honeycomb_value = 1; /* how far to build local for honeycombs */ 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() { EX void test_transducers() {
if(flags & w_skip_transducers) return;
autom.clear(); autom.clear();
int iterations = 0; int iterations = 0;
while(true) { while(true) {
@ -1159,7 +1160,7 @@ EX void test_transducers() {
extract(autom, special[tid][dir], tid, dir); 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; int id = 0;
/* if correct, each loop iteration recovers the identity, so we can build it just once */ /* 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"); println(hlog, "Verifying distances");
map<pair<int, int>, vector< pair<int, int>> > by_roadsign; 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"); if(deflate(&strm, Z_FINISH) != Z_STREAM_END) throw hr_exception("z-error-2");
println(hlog, "deflate ok"); println(hlog, "deflate ok");
string out(&buf[0], (char*)(strm.next_out) - &buf[0]); string out(&buf[0], (char*)(strm.next_out) - &buf[0]);
deflateEnd(&strm);
println(hlog, isize(s), " -> ", isize(out)); println(hlog, isize(s), " -> ", isize(out));
return out; return out;
} }
@ -755,6 +756,7 @@ EX string decompress_string(string s) {
strm.next_out = (Bytef*) &buf[0]; 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]); string out(&buf[0], (char*)(strm.next_out) - &buf[0]);
inflateEnd(&strm);
println(hlog, isize(s), " -> ", isize(out)); println(hlog, isize(s), " -> ", isize(out));
return out; return out;
} }