summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2025-10-20 17:00:31 -0400
committerPeter Zhu <peter@peterzhu.ca>2025-10-21 18:42:17 -0400
commit4a23b6a89fbc7626e31d4cd72b1eccbd0b570009 (patch)
tree6b31c9266a293f540b660157d043407752791a10 /internal
parentcd42096f5a8a15573ccb1e8bcd83872877907541 (diff)
Fix memory leak in RCLASS_SET_NAMESPACE_CLASSEXT
The st_insert in RCLASS_SET_NAMESPACE_CLASSEXT may overwrite an existing rb_classext_t, causing it to leak memory. This commit changes it to use st_update to free the existing one before overwriting it.
Diffstat (limited to 'internal')
-rw-r--r--internal/class.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/internal/class.h b/internal/class.h
index 9fc6d243e6..a791672cad 100644
--- a/internal/class.h
+++ b/internal/class.h
@@ -317,8 +317,7 @@ RCLASS_SET_CLASSEXT_TBL(VALUE klass, st_table *tbl)
rb_classext_t * rb_class_duplicate_classext(rb_classext_t *orig, VALUE obj, const rb_namespace_t *ns);
void rb_class_ensure_writable(VALUE obj);
-void rb_class_classext_free(VALUE klass, rb_classext_t *ext, bool is_prime);
-void rb_iclass_classext_free(VALUE klass, rb_classext_t *ext, bool is_prime);
+void rb_class_set_namespace_classext(VALUE obj, const rb_namespace_t *ns, rb_classext_t *ext);
static inline int
RCLASS_SET_NAMESPACE_CLASSEXT(VALUE obj, const rb_namespace_t *ns, rb_classext_t *ext)
@@ -335,7 +334,9 @@ RCLASS_SET_NAMESPACE_CLASSEXT(VALUE obj, const rb_namespace_t *ns, rb_classext_t
if (rb_st_table_size(tbl) == 0) {
first_set = 1;
}
- rb_st_insert(tbl, (st_data_t)ns->ns_object, (st_data_t)ext);
+
+ rb_class_set_namespace_classext(obj, ns, ext);
+
return first_set;
}
@@ -518,6 +519,9 @@ void rb_undef_methods_from(VALUE klass, VALUE super);
VALUE rb_class_inherited(VALUE, VALUE);
VALUE rb_keyword_error_new(const char *, VALUE);
+void rb_class_classext_free(VALUE klass, rb_classext_t *ext, bool is_prime);
+void rb_iclass_classext_free(VALUE klass, rb_classext_t *ext, bool is_prime);
+
RUBY_SYMBOL_EXPORT_BEGIN
/* for objspace */