From 87865f4c9a6b629a054cd763d2baca7f8132c423 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 20 Dec 2011 09:06:58 +0000 Subject: [PATCH] * fvwrite.c (__sfvwrite_r): Set __SMBF flag to avoid double free in fclose. Enhance comment. --- newlib/ChangeLog | 5 +++++ newlib/libc/stdio/fvwrite.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 8e4dd4258..b54839482 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,8 @@ +2011-12-20 Aleksandr Platonov + + * fvwrite.c (__sfvwrite_r): Set __SMBF flag to avoid double free in + fclose. Enhance comment. + 2011-12-19 Jeff Johnston * NEWS: Update with 1.20.0 info. diff --git a/newlib/libc/stdio/fvwrite.c b/newlib/libc/stdio/fvwrite.c index f196b3cfe..384c62ce0 100644 --- a/newlib/libc/stdio/fvwrite.c +++ b/newlib/libc/stdio/fvwrite.c @@ -155,8 +155,10 @@ _DEFUN(__sfvwrite_r, (ptr, fp, uio), newsize); if (!str) { - /* Free buffer which is no longer used. */ + /* Free buffer which is no longer used and clear + __SMBF flag to avoid double free in fclose. */ _free_r (ptr, fp->_bf._base); + fp->_flags &= ~__SMBF; /* Ensure correct errno, even if free changed it. */ ptr->_errno = ENOMEM; goto err;