summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-05-22 06:50:23 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-05-22 06:50:29 +0900
commit79d9528ddca1dfe2dd99287dc88fd7c2b30f7137 (patch)
tree5ca3c5052d6c045af9c1dc3041714a800a2cc5ce
parent38a4f617de157586668dd726d518eadcebf1bca2 (diff)
downloadruby-79d9528ddca1dfe2dd99287dc88fd7c2b30f7137.tar.gz
Fixed potential memory leak
Create a wrapper object first, then buffer allocation which can fail.
-rw-r--r--compile.c7
-rw-r--r--lib/rubygems/installer.rb1
2 files changed, 5 insertions, 3 deletions
diff --git a/compile.c b/compile.c
index 1159a9d21e..a4328d03fa 100644
--- a/compile.c
+++ b/compile.c
@@ -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