public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* Memory reclaim errors
@ 2023-04-30 22:52 Nick French
  2023-05-02  5:27 ` Sebastian Huber
  0 siblings, 1 reply; 2+ messages in thread
From: Nick French @ 2023-04-30 22:52 UTC (permalink / raw)
  To: newlib

We currently have a problem that when we tidy up a task that exists we
get memory problems due to the fact that we clear memory that is
within newlibs global file handles. The build of newlib that we do is
nano.

We have tracked down an error to what I believe is the following function.

/*
 * Find a free FILE for fopen et al.
 */

FILE *
__sfp (struct _reent *d)
{
  FILE *fp;
  int n;
  struct _glue *g;

  _newlib_sfp_lock_start ();

  if (!_GLOBAL_REENT->__sdidinit)
    __sinit (_GLOBAL_REENT);
  for (g = &_GLOBAL_REENT->__sglue;; g = g->_next)
    {
      for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
        if (fp->_flags == 0)
          goto found;
      if (g->_next == NULL &&
          (g->_next = __sfmoreglue ( d, NDYNAMIC)) == NULL)
        break;
    }
  _newlib_sfp_lock_exit ();

The line below causes us to free the memory as it is assigned to the
current thread

(g->_next = __sfmoreglue ( d, NDYNAMIC)) == NULL)

changing the local thread to global as below fixes it and the file
handle get reused

(g->_next = __sfmoreglue (_GLOBAL_REENT, NDYNAMIC)) == NULL)

Any comments on our assumptions are appreciated.

-- 
*ATTENTION:*
This e-mail and any files transmitted with it are confidential 
and intended solely for the use of the individual or entity to whom they 
are addressed. If you are not the intended recipient, please e-mail the 
sender immediately by replying to this message and delete the material from 
any computer. 
This e-mail is attributed to the sender and may not 
necessarily reflect the view of DVus Ltd, any subsidiary or associate.


_________________________________________
Please consider the environment 
before printing this e-mail



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-02  5:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-30 22:52 Memory reclaim errors Nick French
2023-05-02  5:27 ` Sebastian Huber

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