diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-05-22 06:50:23 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-05-22 06:50:29 +0900 |
commit | 79d9528ddca1dfe2dd99287dc88fd7c2b30f7137 (patch) | |
tree | 5ca3c5052d6c045af9c1dc3041714a800a2cc5ce | |
parent | 38a4f617de157586668dd726d518eadcebf1bca2 (diff) | |
download | ruby-79d9528ddca1dfe2dd99287dc88fd7c2b30f7137.tar.gz |
Fixed potential memory leak
Create a wrapper object first, then buffer allocation which can
fail.
-rw-r--r-- | compile.c | 7 | ||||
-rw-r--r-- | lib/rubygems/installer.rb | 1 |
2 files changed, 5 insertions, 3 deletions
@@ -9721,12 +9721,13 @@ static VALUE pinned_list_new(long size) { struct pinned_list * ptr; + VALUE obj_list = + TypedData_Make_Struct(0, struct pinned_list, &pinned_list_type, ptr); - ptr = xmalloc(sizeof(struct pinned_list)); - ptr->size = size; ptr->buffer = xcalloc(size, sizeof(VALUE)); + ptr->size = size; - return TypedData_Wrap_Struct(0, &pinned_list_type, ptr); + return obj_list; } static ibf_offset_t diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index cf676854dc..cce2967cfd 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -189,6 +189,7 @@ class Gem::Installer if options[:user_install] @gem_home = Gem.user_dir @bin_dir = Gem.bindir gem_home unless options[:bin_dir] + @plugins_dir = Gem.plugindir(gem_home) check_that_user_bin_dir_is_in_path end end |