mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
merge revision(s) c7ce2f537f
: [Backport #20304]
Fix memory leak in setting encodings There is a memory leak 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
This commit is contained in:
parent
db45554fef
commit
519d164b66
2 changed files with 9 additions and 2 deletions
|
@ -1556,7 +1556,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),
|
||||
char *name_dup = strdup(name);
|
||||
|
||||
st_data_t existing_name = (st_data_t)name_dup;
|
||||
if (st_delete(enc_table->names, &existing_name, NULL)) {
|
||||
xfree((void *)existing_name);
|
||||
}
|
||||
|
||||
st_insert(enc_table->names, (st_data_t)name_dup,
|
||||
(st_data_t)UNSPECIFIED_ENCODING);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
||||
#define RUBY_VERSION_TEENY 4
|
||||
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
||||
#define RUBY_PATCHLEVEL 193
|
||||
#define RUBY_PATCHLEVEL 194
|
||||
|
||||
#include "ruby/version.h"
|
||||
#include "ruby/internal/abi.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue