source: rtems/cpukit/libcsupport/src/free.c @ de9b7d7

5
Last change on this file since de9b7d7 was de9b7d7, checked in by Sebastian Huber <sebastian.huber@…>, on 06/01/18 at 05:04:45

Add RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE

An invalid heap usage such as a double free is usually a fatal error
since this indicates a use after free. Replace the use of printk() in
free() with a fatal error.

Update #3437.

  • Property mode set to 100644
File size: 829 bytes
RevLine 
[ceaa999]1/**
2 * @file
[543fe820]3 *
[ceaa999]4 * @brief calloc()
5 * @ingroup libcsupport
6 */
7
8/*
[543fe820]9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
[c499856]14 *  http://www.rtems.org/license/LICENSE.
[543fe820]15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#ifdef RTEMS_NEWLIB
22#include "malloc_p.h"
23#include <stdlib.h>
24
25void free(
26  void *ptr
27)
28{
29  if ( !ptr )
30    return;
31
32  /*
33   *  Do not attempt to free memory if in a critical section or ISR.
34   */
[9d1f3943]35  if ( _Malloc_System_state() != MALLOC_SYSTEM_STATE_NORMAL ) {
36      _Malloc_Deferred_free(ptr);
[543fe820]37      return;
38  }
39
[bd5984de]40  if ( !_Protected_heap_Free( RTEMS_Malloc_Heap, ptr ) ) {
[de9b7d7]41    rtems_fatal( RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE, (rtems_fatal_code) ptr );
[543fe820]42  }
43}
44#endif
Note: See TracBrowser for help on using the repository browser.