This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Hard fault in __free_r


So I was trying to be cleaver, which I should not do....

I have an embedded design where I was creating driver classes.  For low
power I wanted the drivers to get turned off when not in use.  Therefore I
was looking at using smart pointers, and having destructor turn off the
driver.

Note smart pointers as implemented call new and malloc memory on the heap,
but I could write a new template/class that would not.  However I ran into
another problem.

I create some memory for my driver, say UART like so:

uint8_t UartStorage[sizeof(UART)]  __attribute__ ((aligned (8)));

Then I allocate my UART like:

Uart *ptrUart=new(UartStorage) UART(....);

However I have found that sometimes when I call delete on the pointer the
processor will get a hard fault in __free_r.  I could not find the source
for __free_r to see if the static allocation in new was causing a problem
or not, but thought I would post and see if others have seen this?
Also this hard fault was not consistent. That is after allocating and
deleting object a random amount of times from the same static storage
address it would fail.

I took this as a sign I was pushing the bleeding edge a bit too much and
went back to good old static allocation (no new) and just doing an
acquire() and release().

Thanks,
Trampas


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]