diff options
author | Peter Zhu <[email protected]> | 2024-01-03 11:15:44 -0500 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2024-01-03 13:31:43 -0500 |
commit | c7ce2f537f96ab2cf2f5fc2982d6147866ff5340 () | |
tree | 544090b833c9bffe518a5c3b9e16f53d3466e2ef | |
parent | a25329e0dab2a3ada395b1e4e0254a15cd498de2 (diff) |
Fix memory in setting encodings
There is a memory in Encoding.default_external= and Encoding.default_internal= because the duplicated name is not freed when overwriting. 10.times do 1_000_000.times do Encoding.default_internal = nil end puts `ps -o rss= -p #{$$}` end Before: 25664 41504 57360 73232 89168 105056 120944 136816 152720 168576 After: 9648 9648 9648 9680 9680 9680 9680 9680 9680 9680
-rw-r--r-- | encoding.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -1543,7 +1543,14 @@ enc_set_default_encoding(struct default_encoding *def, VALUE encoding, const cha if (NIL_P(encoding)) { def->index = -1; def->enc = 0; - st_insert(enc_table->names, (st_data_t)strdup(name), (st_data_t)UNSPECIFIED_ENCODING); } else { |