Memory reclaim errors

Nick French <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <CAHUKxxX=1pEW9qcyqe=jj7bxjKYiyrpsFc5G3Bi75-unrS=gZA@mail.gmail.com>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.