bugAVR C Runtime Library - Bugs: bug #12557, Non-reentrancy in malloc affects...


bug #12557: Non-reentrancy in malloc affects fprintf, sscanf, etc...

Submitted by:  None
Submitted on:  Tue 05 Apr 2005 02:16:22 AM UTC  
Category:  Library Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  Joerg Wunsch <joerg_wunsch>
Percent Complete:  0% Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  None
Fixed Release:  None

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Tue 06 Sep 2005 07:53:03 PM UTC, comment #1: 

With the recent addition of a malloc()-free stdio API, this
is believed to be fixed as a side-effect.

Joerg Wunsch <joerg_wunsch>
Project AdministratorIn charge of this item.
Tue 05 Apr 2005 02:16:22 AM UTC, original submission:  


I am currently using the runtime library that accompanies WinAVR with my own pre-emptive RTOS. I have used fdevopen() to direct output  to a serial port and an LCD. It is possible for a task that writes to the LCD to be preempted by a task that writes to a serial port, and vice-versa, and either could preempt a user input task that uses sscanf. This is all perfectly reasonable and normal in an embedded system.

Looking at fdevopen(), vfprintf() and vfscanf(), I notice that they all (indirectly) call malloc() (in the latter two cases, when using floating point numbers). This appears to be somewhat problematical, as malloc() does not appear to be reentrant. As far as I can determine, it appears to be possible for one task that is partway through walking the freelist to be preempted by another task that then alters the freelist, before resuming the first task.

I hope that I am wrong, and do not have to implement a workaround*.

I would appreciate your opinion as to whether or not this is a genuine issue.

Kind regards,
Tanya Cumpston

*(The workaround would consist of writing substitutes for the above stdio routines, which attempt to secure a semaphore before calling the existing library routines, then using #defines to redirect calls to the existing library routines to the substitute routines.)



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by joerg_wunsch (Updated the item)



    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-10-22 joerg_wunsch PrivacyPrivate => Public
    2005-09-06 joerg_wunsch StatusNone => Fixed
        Assigned toNone => joerg_wunsch
        Open/ClosedOpen => Closed
    2005-04-05 None Carbon-Copy- => Added tcumpston --AT-- bigpond --DOT-- com

    Back to the top

    Powered by Savane 3.5