This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PTX] malloc/realloc/free
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: Nathan Sidwell <nathan at acm dot org>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 26 May 2016 20:08:51 +0300 (MSK)
- Subject: Re: [PTX] malloc/realloc/free
- Authentication-results: sourceware.org; auth=none
- References: <8f09d389-bd51-cb4a-b491-4eddbe184886 at acm dot org>
Hello,
On Thu, 26 May 2016, Nathan Sidwell wrote:
> This patch removes the malloc/realloc/free wrappers from libgcc. I've
> implemented them completely in C and put them in the ptx newlib port --
> where one expects such functions.
It appears that the new Newlib code doesn't free 'p' on 'realloc (p, 0)';
this is a regression from previous behavior. How about the following fix?
Alexander
diff --git a/newlib/libc/machine/nvptx/realloc.c b/newlib/libc/machine/nvptx/realloc.c
index 634507f..5b6bb62 100644
--- a/newlib/libc/machine/nvptx/realloc.c
+++ b/newlib/libc/machine/nvptx/realloc.c
@@ -34,6 +34,12 @@
void *
realloc (void *old_ptr, size_t new_size)
{
+ if (!new_size)
+ {
+ free (old_ptr);
+ return 0;
+ }
+
void *new_ptr = malloc (new_size);
if (old_ptr && new_ptr)