]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix memory leaks in libio on allocation failure
authorAllan McRae <allan@archlinux.org>
Mon, 9 Sep 2013 12:50:41 +0000 (22:50 +1000)
committerMike Frysinger <vapier@gentoo.org>
Mon, 6 Jan 2014 13:40:04 +0000 (08:40 -0500)
(cherry picked from commit 8e395175c4786ad9679851e3ed3c0c54a6f4e1f0)

libio/memstream.c
libio/wmemstream.c

index 34534e2f94c4a29d66f0e6d76fd6cb8798d9e136..3cb1bd7057de44f11b975c04973c9a4735a5e5ba 100644 (file)
@@ -84,7 +84,10 @@ open_memstream (bufloc, sizeloc)
 
   buf = calloc (1, _IO_BUFSIZ);
   if (buf == NULL)
-    return NULL;
+    {
+      free (new_f);
+      return NULL;
+    }
   _IO_init (&new_f->fp._sf._sbf._f, 0);
   _IO_JUMPS ((struct _IO_FILE_plus *) &new_f->fp._sf._sbf) = &_IO_mem_jumps;
   _IO_str_init_static_internal (&new_f->fp._sf, buf, _IO_BUFSIZ, buf);
index 65738d4d7f241c456309b69d0309b41896ca7def..fd7fe44c4c34d76af8a5375a2b6644a5238f0cae 100644 (file)
@@ -85,8 +85,10 @@ open_wmemstream (bufloc, sizeloc)
 
   buf = calloc (1, _IO_BUFSIZ);
   if (buf == NULL)
-    return NULL;
-
+    {
+      free (new_f);
+      return NULL;
+    }
   _IO_no_init (&new_f->fp._sf._sbf._f, 0, 0, &new_f->wd, &_IO_wmem_jumps);
   _IO_fwide (&new_f->fp._sf._sbf._f, 1);
   _IO_wstr_init_static (&new_f->fp._sf._sbf._f, buf,