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

* Re: Memory reclaim errors
  2023-04-30 22:52 Memory reclaim errors Nick French
@ 2023-05-02  5:27 ` Sebastian Huber
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Huber @ 2023-05-02  5:27 UTC (permalink / raw)
  To: Nick French, newlib

Hello Nick,

On 01.05.23 00:52, Nick French wrote:
> 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.

does this mean the memory allocator used for

static struct _glue *
sfmoreglue (struct _reent *d, int n)
{
   struct glue_with_file *g;

   g = (struct glue_with_file *)
     _malloc_r (d, sizeof (*g) + (n - 1) * sizeof (FILE));
   if (g == NULL)
     return NULL;
   g->glue._next = NULL;
   g->glue._niobs = n;
   g->glue._iobs = &g->file;
   memset (&g->file, 0, n * sizeof (FILE));
   return &g->glue;
}

somehow supports thread-specific memory which is automatically freed 
when the associated thread is terminated?

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

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