public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Correct argz_replace behaviour when memory is exhausted.
@ 2015-06-01  8:10 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2015-06-01  8:10 UTC (permalink / raw)
  To: newlib-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=8fe35bd15fe8408d0f6934b7e4e639614b6407ba

commit 8fe35bd15fe8408d0f6934b7e4e639614b6407ba
Author: David Stacey <drstacey@tiscali.co.uk>
Date:   Mon Jun 1 10:09:04 2015 +0200

    Correct argz_replace behaviour when memory is exhausted.
    
    	* libc/argz/argz_replace.c (argz_replace): Correct behaviour when memory
    	is exhausted.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 newlib/ChangeLog                | 5 +++++
 newlib/libc/argz/argz_replace.c | 7 +++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 632f2ac..a985058 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,8 @@
+2015-05-31  David Stacey  <drstacey@tiscali.co.uk>
+
+	* libc/argz/argz_replace.c (argz_replace): Correct behaviour when memory
+	is exhausted.
+
 2015-05-28  Corinna Vinschen  <vinschen@redhat.com>
 
 	* libc/include/sys/wait.h: Fix comment.
diff --git a/newlib/libc/argz/argz_replace.c b/newlib/libc/argz/argz_replace.c
index 6bfd04b..b274f91 100644
--- a/newlib/libc/argz/argz_replace.c
+++ b/newlib/libc/argz/argz_replace.c
@@ -30,6 +30,7 @@ _DEFUN (argz_replace, (argz, argz_len, str, with, replace_count),
   char *new_argz = NULL;
   size_t new_argz_len = 0;
   char *new_argz_iter = NULL;
+  char *argz_realloc = NULL;
 
   *replace_count = 0;
   new_argz_len = *argz_len;
@@ -45,7 +46,8 @@ _DEFUN (argz_replace, (argz, argz_len, str, with, replace_count),
 
   if (*replace_count)
     {
-      new_argz = (char *)malloc(new_argz_len);
+      if (!(new_argz = (char *)malloc(new_argz_len)))
+	return ENOMEM;
       
       buf_iter = *argz;
       buf_len = *argz_len;
@@ -70,11 +72,12 @@ _DEFUN (argz_replace, (argz, argz_len, str, with, replace_count),
       memcpy(new_argz_iter, last_iter, *argz + *argz_len - last_iter);
 
       /* reallocate argz, and copy over the new value. */
-      if(!(*argz = (char *)realloc(*argz, new_argz_len)))
+      if(!(argz_realloc = (char *)realloc(*argz, new_argz_len)))
         {
           free(new_argz);
           return ENOMEM;
         }
+      *argz = argz_realloc;
 
       memcpy(*argz, new_argz, new_argz_len);
       *argz_len = new_argz_len;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-06-01  8:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-01  8:10 [newlib-cygwin] Correct argz_replace behaviour when memory is exhausted Corinna Vinschen

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).