public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Nick French <nick.french@dvus.co.uk>
To: newlib@sourceware.org
Subject: Memory reclaim errors
Date: Sun, 30 Apr 2023 23:52:39 +0100	[thread overview]
Message-ID: <CAHUKxxX=1pEW9qcyqe=jj7bxjKYiyrpsFc5G3Bi75-unrS=gZA@mail.gmail.com> (raw)

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



             reply	other threads:[~2023-04-30 22:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-30 22:52 Nick French [this message]
2023-05-02  5:27 ` Sebastian Huber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHUKxxX=1pEW9qcyqe=jj7bxjKYiyrpsFc5G3Bi75-unrS=gZA@mail.gmail.com' \
    --to=nick.french@dvus.co.uk \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).