This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Freeing std streams when using _REENT_SMALL


Hello,

The stdin, stdout and stderr streams are created in __sinit. In the case of _REENT_SMALL, they are not entered into the __sglue list:

#ifndef _REENT_SMALL
  s->__sglue._niobs = 3;
  s->__sglue._iobs = &s->__sf[0];
#else
  s->__sglue._niobs = 0;
  s->__sglue._iobs = NULL;
  s->_stdin = __sfp(s);
  s->_stdout = __sfp(s);
  s->_stderr = __sfp(s);
#endif

Because the std streams are not in __sglue, the __cleanup function will not call fclose on them. The following patch fixes this by calling fclose on the streams manually. That may not be the best way to fix it so any other suggestions are welcome.

Cheers,
 Hans-Erik Floryd

diff -Naur newlib-1.17.0/newlib/libc/reent/reent.c newlib-1.17.0-mod/newlib/libc/reent/reent.c
--- newlib-1.17.0/newlib/libc/reent/reent.c 2006-10-11 10:04:50.000000000 +0200
+++ newlib-1.17.0-mod/newlib/libc/reent/reent.c 2009-03-27 11:23:27.000000000 +0100
@@ -143,5 +143,14 @@
#endif
if (ptr->__cleanup)
(*ptr->__cleanup) (ptr);
+
+#ifdef _REENT_SMALL
+ if (ptr->__sdidinit)
+ {
+ _fclose_r (ptr, ptr->_stdin);
+ _fclose_r (ptr, ptr->_stdout);
+ _fclose_r (ptr, ptr->_stderr);
+ }
+#endif
}




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]