Merge branch 'sh-add-ruby-bug-19580-patches' into 'master'

Add Ruby patch for https://bugs.ruby-lang.org/issues/19580

See merge request https://gitlab.com/gitlab-org/gitlab-build-images/-/merge_requests/672

Merged-by: Rémy Coutable <remy@rymai.me>
Approved-by: Rémy Coutable <remy@rymai.me>
Approved-by: Matthias Käppler <mkaeppler@gitlab.com>
Co-authored-by: Stan Hu <stanhu@gmail.com>
This commit is contained in:
Rémy Coutable 2023-04-14 08:20:13 +00:00
commit 24deb3db06
6 changed files with 94 additions and 0 deletions

View file

@ -8,6 +8,7 @@
- changes:
- "scripts/lib/custom-docker-build"
- ".gitlab/ci/gitlab.images.yml"
- "patches/ruby/**/*"
gitlab:
extends:

View file

@ -0,0 +1,23 @@
diff --git a/gc.c b/gc.c
index 67a709ff79..98785901f4 100644
--- a/gc.c
+++ b/gc.c
@@ -10174,8 +10174,16 @@ ruby_xrealloc2_body(void *ptr, size_t n, size_t size)
void
ruby_sized_xfree(void *x, size_t size)
{
- if (x) {
- objspace_xfree(&rb_objspace, x, size);
+ if (LIKELY(x)) {
+ /* It's possible for a C extension's pthread destructor function set by pthread_key_create
+ * to be called after ruby_vm_destruct and attempt to free memory. Fall back to mimfree in
+ * that case. */
+ if (LIKELY(GET_VM())) {
+ objspace_xfree(&rb_objspace, x, size);
+ }
+ else {
+ ruby_mimfree(x);
+ }
}
}

View file

@ -0,0 +1,23 @@
diff --git a/gc.c b/gc.c
index 5d0c342206..2bfff21004 100644
--- a/gc.c
+++ b/gc.c
@@ -10905,8 +10905,16 @@ ruby_xrealloc2_body(void *ptr, size_t n, size_t size)
void
ruby_sized_xfree(void *x, size_t size)
{
- if (x) {
- objspace_xfree(&rb_objspace, x, size);
+ if (LIKELY(x)) {
+ /* It's possible for a C extension's pthread destructor function set by pthread_key_create
+ * to be called after ruby_vm_destruct and attempt to free memory. Fall back to mimfree in
+ * that case. */
+ if (LIKELY(GET_VM())) {
+ objspace_xfree(&rb_objspace, x, size);
+ }
+ else {
+ ruby_mimfree(x);
+ }
}
}

View file

@ -0,0 +1,23 @@
diff --git a/gc.c b/gc.c
index 030a4627bd..1c96f6401f 100644
--- a/gc.c
+++ b/gc.c
@@ -11763,8 +11763,16 @@ ruby_xrealloc2_body(void *ptr, size_t n, size_t size)
void
ruby_sized_xfree(void *x, size_t size)
{
- if (x) {
- objspace_xfree(&rb_objspace, x, size);
+ if (LIKELY(x)) {
+ /* It's possible for a C extension's pthread destructor function set by pthread_key_create
+ * to be called after ruby_vm_destruct and attempt to free memory. Fall back to mimfree in
+ * that case. */
+ if (LIKELY(GET_VM())) {
+ objspace_xfree(&rb_objspace, x, size);
+ }
+ else {
+ ruby_mimfree(x);
+ }
}
}

View file

@ -0,0 +1,23 @@
diff --git a/gc.c b/gc.c
index 54400e4f6b..96d43ac8ac 100644
--- a/gc.c
+++ b/gc.c
@@ -12614,8 +12614,16 @@ ruby_xrealloc2_body(void *ptr, size_t n, size_t size)
void
ruby_sized_xfree(void *x, size_t size)
{
- if (x) {
- objspace_xfree(&rb_objspace, x, size);
+ if (LIKELY(x)) {
+ /* It's possible for a C extension's pthread destructor function set by pthread_key_create
+ * to be called after ruby_vm_destruct and attempt to free memory. Fall back to mimfree in
+ * that case. */
+ if (LIKELY(GET_VM())) {
+ objspace_xfree(&rb_objspace, x, size);
+ }
+ else {
+ ruby_mimfree(x);
+ }
}
}

View file

@ -1 +1,2 @@
thread-memory-allocations
fix-ruby-xfree-for-libxml2