public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/omp/gcc-12] In 'libgomp/allocator.c:omp_realloc', route 'free' through 'MEMSPACE_FREE'
Date: Thu, 16 Feb 2023 21:42:17 +0000 (GMT)	[thread overview]
Message-ID: <20230216214217.7DAD63858D33@sourceware.org> (raw)

https://gcc.gnu.org/g:3a2c07395b0a565955a7b86f0eba866937e15989

commit 3a2c07395b0a565955a7b86f0eba866937e15989
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Tue Feb 14 13:35:03 2023 +0100

    In 'libgomp/allocator.c:omp_realloc', route 'free' through 'MEMSPACE_FREE'
    
    ... to not run into a SIGSEGV if a non-'malloc'-based allocation is 'free'd
    here.
    
    Fix-up for og12 commit c5d1d7651297a273321154a5fe1b01eba9dcf604
    "libgomp, nvptx: low-latency memory allocator".
    
            libgomp/
            * allocator.c (omp_realloc): Route 'free' through 'MEMSPACE_FREE'.

Diff:
---
 libgomp/ChangeLog.omp |  2 ++
 libgomp/allocator.c   | 12 +++++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 530f5c6acf6..819a5333907 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,5 +1,7 @@
 2023-02-16  Thomas Schwinge  <thomas@codesourcery.com>
 
+	* allocator.c (omp_realloc): Route 'free' through 'MEMSPACE_FREE'.
+
 	* config/linux/allocator.c (linux_memspace_alloc)
 	(linux_memspace_calloc): Clarify zero-initialization for pinned
 	memory.
diff --git a/libgomp/allocator.c b/libgomp/allocator.c
index 05b323d458e..ba9a4e17cc2 100644
--- a/libgomp/allocator.c
+++ b/libgomp/allocator.c
@@ -854,7 +854,17 @@ retry:
       gomp_mutex_unlock (&free_allocator_data->lock);
 #endif
     }
-  free (data->ptr);
+  {
+    omp_memspace_handle_t was_memspace __attribute__((unused))
+      = (free_allocator_data
+	 ? free_allocator_data->memspace
+	 : predefined_alloc_mapping[free_allocator]);
+    int was_pinned __attribute__((unused))
+      = (free_allocator_data
+	 ? free_allocator_data->pinned
+	 : free_allocator == ompx_pinned_mem_alloc);
+    MEMSPACE_FREE (was_memspace, data->ptr, data->size, was_pinned);
+  }
   return ret;
 
 fail:

                 reply	other threads:[~2023-02-16 21:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230216214217.7DAD63858D33@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).