From fa818d423b5ce74fa78ed01195adab80dbaa4277 Mon Sep 17 00:00:00 2001
From: winckel <winckel@eurecom.fr>
Date: Fri, 20 Dec 2013 09:14:19 +0000
Subject: [PATCH] Added an action parameter to be performed when assert fails
 in AssertError. Added a return status to itti_free.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4779 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 common/utils/assertions.h                    | 44 ++++++-----
 common/utils/itti/assertions.h               | 41 +++++-----
 common/utils/itti/intertask_interface.c      | 83 ++++++++++----------
 common/utils/itti/intertask_interface.h      |  2 +-
 common/utils/itti/intertask_interface_dump.c | 52 ++++++------
 common/utils/itti/memory_pools.c             | 76 +++++++++++-------
 common/utils/itti/memory_pools.h             |  2 +-
 common/utils/itti/timer.c                    |  2 +-
 openair-cn/NAS/nas_ue_task.c                 |  8 +-
 9 files changed, 172 insertions(+), 138 deletions(-)

diff --git a/common/utils/assertions.h b/common/utils/assertions.h
index 5518e765a56..96d19152b0e 100644
--- a/common/utils/assertions.h
+++ b/common/utils/assertions.h
@@ -34,38 +34,42 @@
 #include <stdint.h>
 #include <inttypes.h>
 
-#define _Assert_(cOND, eXIT, fORMAT, aRGS...)                               \
-do {                                                                        \
-    if (!(cOND)) {                                                          \
-        fprintf(stderr, "%s:%d:%s Assertion `"#cOND"` failed!\n" fORMAT,    \
-                __FILE__, __LINE__, __FUNCTION__, ##aRGS);                  \
-        if (eXIT != 0) {                                                    \
-            fprintf(stderr, "Exiting execution\n");                         \
-            fflush(stdout);                                                 \
-            fflush(stderr);                                                 \
-            abort();                                                        \
-        }                                                                   \
-    }                                                                       \
+#define _Assert_Exit_                           \
+{                                               \
+    fprintf(stderr, "\nExiting execution\n");   \
+    fflush(stdout);                             \
+    fflush(stderr);                             \
+    abort();                                    \
+}
+
+#define _Assert_(cOND, aCTION, fORMAT, aRGS...)             \
+do {                                                        \
+    if (!(cOND)) {                                          \
+        fprintf(stderr, "\nAssertion ("#cOND") failed!\n"   \
+                "In %s() %s:%d\n" fORMAT,                   \
+                __FUNCTION__, __FILE__, __LINE__, ##aRGS);  \
+        aCTION;                                             \
+    }                                                       \
 } while(0)
 
-#define AssertFatal(cOND, fORMAT, aRGS...)  _Assert_(cOND, 1, fORMAT, ##aRGS)
+#define AssertFatal(cOND, fORMAT, aRGS...)          _Assert_(cOND, _Assert_Exit_, fORMAT, ##aRGS)
 
-#define AssertError(cOND, fORMAT, aRGS...)  _Assert_(cOND, 0, fORMAT, ##aRGS)
+#define AssertError(cOND, aCTION, fORMAT, aRGS...)  _Assert_(cOND, aCTION, fORMAT, ##aRGS)
 
 
 
-#define DevCheck(cOND, vALUE1, vALUE2, vALUE3)                                              \
-_Assert_(cOND, 1, #vALUE1": %"PRIdMAX"\n"#vALUE2": %"PRIdMAX"\n"#vALUE3": %"PRIdMAX"\n\n",  \
+#define DevCheck(cOND, vALUE1, vALUE2, vALUE3)                                                          \
+_Assert_(cOND, _Assert_Exit_, #vALUE1": %"PRIdMAX"\n"#vALUE2": %"PRIdMAX"\n"#vALUE3": %"PRIdMAX"\n\n",  \
          (intmax_t)vALUE1, (intmax_t)vALUE2, (intmax_t)vALUE3)
 
-#define DevCheck4(cOND, vALUE1, vALUE2, vALUE3, vALUE4)                                                             \
-_Assert_(cOND, 1, #vALUE1": %"PRIdMAX"\n"#vALUE2": %"PRIdMAX"\n"#vALUE3": %"PRIdMAX"\n"#vALUE4": %"PRIdMAX"\n\n",   \
+#define DevCheck4(cOND, vALUE1, vALUE2, vALUE3, vALUE4)                                                                         \
+_Assert_(cOND, _Assert_Exit_, #vALUE1": %"PRIdMAX"\n"#vALUE2": %"PRIdMAX"\n"#vALUE3": %"PRIdMAX"\n"#vALUE4": %"PRIdMAX"\n\n",   \
          (intmax_t)vALUE1, (intmax_t)vALUE2, (intmax_t)vALUE3, (intmax_t)vALUE4)
 
 #define DevParam(vALUE1, vALUE2, vALUE3)    DevCheck(0, vALUE1, vALUE2, vALUE3)
 
-#define DevAssert(cOND)                     _Assert_(cOND, 1, "")
+#define DevAssert(cOND)                     _Assert_(cOND, _Assert_Exit_, "")
 
-#define DevMessage(mESSAGE)                 _Assert_(0, 1, #mESSAGE)
+#define DevMessage(mESSAGE)                 _Assert_(0, _Assert_Exit_, #mESSAGE)
 
 #endif /* ASSERTIONS_H_ */
diff --git a/common/utils/itti/assertions.h b/common/utils/itti/assertions.h
index 2bc72f058f3..a01b60f3e67 100644
--- a/common/utils/itti/assertions.h
+++ b/common/utils/itti/assertions.h
@@ -39,35 +39,40 @@
 #ifndef ASSERTIONS_H_
 #define ASSERTIONS_H_
 
-#define _Assert_(cOND, eXIT, fORMAT, aRGS...)                               \
-do {                                                                        \
-    if (!(cOND)) {                                                          \
-        fprintf(stderr, "%s:%d:%s Assertion `"#cOND"` failed!\n" fORMAT,    \
-                __FILE__, __LINE__, __FUNCTION__, ##aRGS);                  \
-        if (eXIT != 0) {                                                    \
-            display_backtrace();                                            \
-            fflush(stdout);                                                 \
-            fflush(stderr);                                                 \
-            exit(EXIT_FAILURE);                                             \
-        }                                                                   \
-    }                                                                       \
+#define _Assert_Exit_                           \
+{                                               \
+    fprintf(stderr, "\nExiting execution\n");   \
+    display_backtrace();                        \
+    fflush(stdout);                             \
+    fflush(stderr);                             \
+    exit(EXIT_FAILURE);                         \
+}
+
+#define _Assert_(cOND, aCTION, fORMAT, aRGS...)             \
+do {                                                        \
+    if (!(cOND)) {                                          \
+        fprintf(stderr, "\nAssertion ("#cOND") failed!\n"   \
+                "In %s() %s:%d\n" fORMAT,                   \
+                __FUNCTION__, __FILE__, __LINE__, ##aRGS);  \
+        aCTION;                                             \
+    }                                                       \
 } while(0)
 
-#define AssertFatal(cOND, fORMAT, aRGS...)  _Assert_(cOND, 1, fORMAT, ##aRGS)
+#define AssertFatal(cOND, fORMAT, aRGS...)          _Assert_(cOND, _Assert_Exit_, fORMAT, ##aRGS)
 
-#define AssertError(cOND, fORMAT, aRGS...)  _Assert_(cOND, 0, fORMAT, ##aRGS)
+#define AssertError(cOND, aCTION, fORMAT, aRGS...)  _Assert_(cOND, aCTION, fORMAT, ##aRGS)
 
 
 
-#define DevCheck(cOND, vALUE1, vALUE2, vALUE3)                              \
-_Assert_(cOND, 1, #vALUE1": %d\n"#vALUE2": %d\n"#vALUE3": %d\n\n",          \
+#define DevCheck(cOND, vALUE1, vALUE2, vALUE3)                                  \
+_Assert_(cOND, _Assert_Exit_, #vALUE1": %d\n"#vALUE2": %d\n"#vALUE3": %d\n\n",  \
          (int)vALUE1, (int)vALUE2, (int)vALUE3)
 
 #define DevParam(vALUE1, vALUE2, vALUE3)    DevCheck(0, vALUE1, vALUE2, vALUE3)
 
-#define DevAssert(cOND)                     _Assert_(cOND, 1, "")
+#define DevAssert(cOND)                     _Assert_(cOND, _Assert_Exit_, "")
 
-#define DevMessage(mESSAGE)                 _Assert_(0, 1, #mESSAGE)
+#define DevMessage(mESSAGE)                 _Assert_(0, _Assert_Exit_, #mESSAGE)
 
 #define CHECK_INIT_RETURN(fCT)                                  \
 do {                                                            \
diff --git a/common/utils/itti/intertask_interface.c b/common/utils/itti/intertask_interface.c
index 1a41adde467..cc1cd468ee1 100644
--- a/common/utils/itti/intertask_interface.c
+++ b/common/utils/itti/intertask_interface.c
@@ -80,14 +80,12 @@ const int itti_debug = ITTI_DEBUG_ISSUES | ITTI_DEBUG_MP_STATISTICS;
 #ifdef RTAI
 # define ITTI_DEBUG(m, x, args...) do { if ((m) & itti_debug) rt_printk("[ITTI][D]"x, ##args); } \
     while(0)
-# define ITTI_ERROR(x, args...) do { rt_printk("[ITTI][E]"x, ##args); } \
-    while(0)
 #else
 # define ITTI_DEBUG(m, x, args...) do { if ((m) & itti_debug) fprintf(stdout, "[ITTI][D]"x, ##args); fflush (stdout); } \
     while(0)
-# define ITTI_ERROR(x, args...) do { fprintf(stdout, "[ITTI][E]"x, ##args); fflush (stdout); } \
-    while(0)
 #endif
+#define ITTI_ERROR(x, args...) do { fprintf(stdout, "[ITTI][E]"x, ##args); fflush (stdout); } \
+    while(0)
 
 /* Global message size */
 #define MESSAGE_SIZE(mESSAGEiD) (sizeof(MessageHeader) + itti_desc.messages_info[mESSAGEiD].size)
@@ -211,20 +209,25 @@ void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize
     ptr = malloc (size);
 #endif
 
-    AssertFatal (ptr != NULL, "Memory allocation of %d bytes failed (%d -> %d)\n", (int) size, origin_task_id, destination_task_id);
+    AssertFatal (ptr != NULL, "Memory allocation of %d bytes failed (%d -> %d)!\n", (int) size, origin_task_id, destination_task_id);
 
     return ptr;
 }
 
-void itti_free(task_id_t task_id, void *ptr)
+int itti_free(task_id_t task_id, void *ptr)
 {
-    AssertFatal (ptr != NULL, "Trying to free a NULL pointer (%d)\n", task_id);
+    int result = EXIT_SUCCESS;
+    AssertFatal (ptr != NULL, "Trying to free a NULL pointer (%d)!\n", task_id);
 
 #if defined(OAI_EMU) || defined(RTAI)
-    memory_pools_free (itti_desc.memory_pools_handle, ptr, task_id);
+    result = memory_pools_free (itti_desc.memory_pools_handle, ptr, task_id);
+
+    AssertError (result == EXIT_SUCCESS, {}, "Failed to free memory at %p (%d)!\n", ptr, task_id);
 #else
     free (ptr);
 #endif
+
+    return (result);
 }
 
 static inline message_number_t itti_increment_message_number(void) {
@@ -236,20 +239,20 @@ static inline message_number_t itti_increment_message_number(void) {
 }
 
 static inline uint32_t itti_get_message_priority(MessagesIds message_id) {
-    AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)\n", message_id, itti_desc.messages_id_max);
+    AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)!\n", message_id, itti_desc.messages_id_max);
 
     return (itti_desc.messages_info[message_id].priority);
 }
 
 const char *itti_get_message_name(MessagesIds message_id) {
-    AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)\n", message_id, itti_desc.messages_id_max);
+    AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)!\n", message_id, itti_desc.messages_id_max);
 
     return (itti_desc.messages_info[message_id].name);
 }
 
 const char *itti_get_task_name(task_id_t task_id)
 {
-    AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)\n", task_id, itti_desc.task_max);
+    AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)!\n", task_id, itti_desc.task_max);
 
     return (itti_desc.tasks_info[task_id].name);
 }
@@ -286,7 +289,7 @@ int itti_send_broadcast_message(MessageDef *message_p) {
     int ret = 0;
     int result;
 
-    AssertFatal (message_p != NULL, "Trying to broadcast a NULL message\n");
+    AssertFatal (message_p != NULL, "Trying to broadcast a NULL message!\n");
 
     origin_task_id = message_p->ittiMsgHeader.originTaskId;
     origin_thread_id = TASK_GET_THREAD_ID(origin_task_id);
@@ -304,11 +307,11 @@ int itti_send_broadcast_message(MessageDef *message_p) {
             /* Skip tasks which are not running */
             if (itti_desc.threads[thread_id].task_state == TASK_STATE_READY) {
                 new_message_p = itti_malloc (origin_task_id, destination_task_id, sizeof(MessageDef));
-                AssertFatal (new_message_p != NULL, "New message allocation failed\n");
+                AssertFatal (new_message_p != NULL, "New message allocation failed!\n");
 
                 memcpy (new_message_p, message_p, sizeof(MessageDef));
                 result = itti_send_msg_to_task (destination_task_id, INSTANCE_DEFAULT, new_message_p);
-                AssertFatal (result >= 0, "Failed to send message %d to thread %d (task %d)\n", message_p->ittiMsgHeader.messageId, thread_id, destination_task_id);
+                AssertFatal (result >= 0, "Failed to send message %d to thread %d (task %d)!\n", message_p->ittiMsgHeader.messageId, thread_id, destination_task_id);
             }
         }
     }
@@ -321,7 +324,7 @@ inline MessageDef *itti_alloc_new_message_sized(task_id_t origin_task_id, Messag
 {
     MessageDef *temp = NULL;
 
-    AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)\n", message_id, itti_desc.messages_id_max);
+    AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)!\n", message_id, itti_desc.messages_id_max);
 
 #if defined(OAI_EMU) || defined(RTAI)
     vcd_signal_dumper_dump_variable_by_name(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_ALLOC_MSG, size);
@@ -365,7 +368,7 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
                                             __sync_or_and_fetch (&itti_desc.vcd_send_msg, 1L << destination_task_id));
 #endif
 
-    AssertFatal (message != NULL, "Message is NULL\n");
+    AssertFatal (message != NULL, "Message is NULL!\n");
     AssertFatal (destination_task_id < itti_desc.task_max, "Destination task id (%d) is out of range (%d)\n", destination_task_id, itti_desc.task_max);
 
     destination_thread_id = TASK_GET_THREAD_ID(destination_task_id);
@@ -374,7 +377,7 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
     message->ittiMsgHeader.lte_time.frame = itti_desc.lte_time.frame;
     message->ittiMsgHeader.lte_time.slot = itti_desc.lte_time.slot;
     message_id = message->ittiMsgHeader.messageId;
-    AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)\n", message_id, itti_desc.messages_id_max);
+    AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)!\n", message_id, itti_desc.messages_id_max);
 
     origin_task_id = ITTI_MSG_ORIGIN_ID(message);
 
@@ -407,7 +410,7 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
         else
         {
             /* We cannot send a message if the task is not running */
-            AssertFatal (itti_desc.threads[destination_thread_id].task_state == TASK_STATE_READY, "Cannot send message %d to thread %d, it is not in ready state (%d)\n",
+            AssertFatal (itti_desc.threads[destination_thread_id].task_state == TASK_STATE_READY, "Cannot send message %d to thread %d, it is not in ready state (%d)!\n",
                          message_id, destination_thread_id, itti_desc.threads[destination_thread_id].task_state);
 
             /* Allocate new list element */
@@ -473,7 +476,7 @@ void itti_subscribe_event_fd(task_id_t task_id, int fd)
     thread_id_t thread_id;
     struct epoll_event event;
 
-    AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)\n", task_id, itti_desc.task_max);
+    AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)!\n", task_id, itti_desc.task_max);
 
     thread_id = TASK_GET_THREAD_ID(task_id);
     itti_desc.threads[thread_id].nb_events++;
@@ -492,7 +495,7 @@ void itti_subscribe_event_fd(task_id_t task_id, int fd)
         &event) != 0)
     {
         /* Always assert on this condition */
-        AssertFatal (0, "epoll_ctl (EPOLL_CTL_ADD) failed for task %s, fd %d: %s\n",
+        AssertFatal (0, "epoll_ctl (EPOLL_CTL_ADD) failed for task %s, fd %d: %s!\n",
                      itti_get_task_name(task_id), fd, strerror(errno));
     }
 
@@ -503,15 +506,15 @@ void itti_unsubscribe_event_fd(task_id_t task_id, int fd)
 {
     thread_id_t thread_id;
 
-    AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)\n", task_id, itti_desc.task_max);
-    AssertFatal (fd >= 0, "File descriptor (%d) is invalid\n", fd);
+    AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)!\n", task_id, itti_desc.task_max);
+    AssertFatal (fd >= 0, "File descriptor (%d) is invalid!\n", fd);
 
     thread_id = TASK_GET_THREAD_ID(task_id);
     /* Add the event fd to the list of monitored events */
     if (epoll_ctl(itti_desc.threads[thread_id].epoll_fd, EPOLL_CTL_DEL, fd, NULL) != 0)
     {
         /* Always assert on this condition */
-        AssertFatal (0, "epoll_ctl (EPOLL_CTL_DEL) failed for task %s, fd %d: %s\n",
+        AssertFatal (0, "epoll_ctl (EPOLL_CTL_DEL) failed for task %s, fd %d: %s!\n",
                      itti_get_task_name(task_id), fd, strerror(errno));
     }
 
@@ -540,8 +543,8 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
     int epoll_timeout = 0;
     int i;
 
-    AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)\n", task_id, itti_desc.task_max);
-    AssertFatal (received_msg != NULL, "Received message is NULL\n");
+    AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)!\n", task_id, itti_desc.task_max);
+    AssertFatal (received_msg != NULL, "Received message is NULL!\n");
 
     thread_id = TASK_GET_THREAD_ID(task_id);
     *received_msg = NULL;
@@ -565,7 +568,7 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
     } while (epoll_ret < 0 && errno == EINTR);
 
     if (epoll_ret < 0) {
-        AssertFatal (0, "epoll_wait failed for task %s: %s\n", itti_get_task_name(task_id), strerror(errno));
+        AssertFatal (0, "epoll_wait failed for task %s: %s!\n", itti_get_task_name(task_id), strerror(errno));
     }
     if (epoll_ret == 0 && polling) {
         /* No data to read -> return */
@@ -585,7 +588,7 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
 
             /* Read will always return 1 */
             read_ret = read (itti_desc.threads[thread_id].task_event_fd, &sem_counter, sizeof(sem_counter));
-            AssertFatal (read_ret == sizeof(sem_counter), "Read from task message FD (%d) failed (%d/%d)\n", thread_id, (int) read_ret, (int) sizeof(sem_counter));
+            AssertFatal (read_ret == sizeof(sem_counter), "Read from task message FD (%d) failed (%d/%d)!\n", thread_id, (int) read_ret, (int) sizeof(sem_counter));
 
 #if defined(KERNEL_VERSION_PRE_2_6_30)
             /* Store the value of the semaphore counter */
@@ -594,9 +597,9 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
 
             if (lfds611_queue_dequeue (itti_desc.tasks[task_id].message_queue, (void **) &message) == 0) {
                 /* No element in list -> this should not happen */
-                AssertFatal (0, "No message in queue for task %d while there are %d events and some for the messages queue\n", task_id, epoll_ret);
+                AssertFatal (0, "No message in queue for task %d while there are %d events and some for the messages queue!\n", task_id, epoll_ret);
             }
-            AssertFatal(message != NULL, "Message from message queue is NULL\n");
+            AssertFatal(message != NULL, "Message from message queue is NULL!\n");
             *received_msg = message->msg;
             itti_free (ITTI_MSG_ORIGIN_ID(*received_msg), message);
             /* Mark that the event has been processed */
@@ -638,7 +641,7 @@ void itti_receive_msg(task_id_t task_id, MessageDef **received_msg)
 }
 
 void itti_poll_msg(task_id_t task_id, MessageDef **received_msg) {
-    AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)\n", task_id, itti_desc.task_max);
+    AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)!\n", task_id, itti_desc.task_max);
 
     *received_msg = NULL;
 
@@ -671,9 +674,9 @@ int itti_create_task(task_id_t task_id, void *(*start_routine)(void *), void *ar
     thread_id_t thread_id = TASK_GET_THREAD_ID(task_id);
     int result;
 
-    AssertFatal (start_routine != NULL, "Start routine is NULL\n");
-    AssertFatal (thread_id < itti_desc.thread_max, "Thread id (%d) is out of range (%d)\n", thread_id, itti_desc.thread_max);
-    AssertFatal (itti_desc.threads[thread_id].task_state == TASK_STATE_NOT_CONFIGURED, "Task %d, thread %d state is not correct (%d)\n",
+    AssertFatal (start_routine != NULL, "Start routine is NULL!\n");
+    AssertFatal (thread_id < itti_desc.thread_max, "Thread id (%d) is out of range (%d)!\n", thread_id, itti_desc.thread_max);
+    AssertFatal (itti_desc.threads[thread_id].task_state == TASK_STATE_NOT_CONFIGURED, "Task %d, thread %d state is not correct (%d)!\n",
                  task_id, thread_id, itti_desc.threads[thread_id].task_state);
 
     itti_desc.threads[thread_id].task_state = TASK_STATE_STARTING;
@@ -681,7 +684,7 @@ int itti_create_task(task_id_t task_id, void *(*start_routine)(void *), void *ar
     ITTI_DEBUG(ITTI_DEBUG_INIT, " Creating thread for task %s ...\n", itti_get_task_name(task_id));
 
     result = pthread_create (&itti_desc.threads[thread_id].task_thread, NULL, start_routine, args_p);
-    AssertFatal (result >= 0, "Thread creation for task %d, thread %d failed (%d)\n", task_id, thread_id, result);
+    AssertFatal (result >= 0, "Thread creation for task %d, thread %d failed (%d)!\n", task_id, thread_id, result);
 
     itti_desc.created_tasks ++;
 
@@ -710,7 +713,7 @@ void itti_wait_ready(int wait_tasks)
     ITTI_DEBUG(ITTI_DEBUG_INIT, " wait for tasks: %s, created tasks %d, ready tasks %d\n", itti_desc.wait_tasks ? "yes" : "no",
         itti_desc.created_tasks, itti_desc.ready_tasks);
 
-    AssertFatal (itti_desc.created_tasks == itti_desc.ready_tasks, "Number of created tasks (%d) does not match ready tasks (%d), wait task %d\n",
+    AssertFatal (itti_desc.created_tasks == itti_desc.ready_tasks, "Number of created tasks (%d) does not match ready tasks (%d), wait task %d!\n",
                  itti_desc.created_tasks, itti_desc.ready_tasks, itti_desc.wait_tasks);
 }
 
@@ -718,7 +721,7 @@ void itti_mark_task_ready(task_id_t task_id)
 {
     thread_id_t thread_id = TASK_GET_THREAD_ID(task_id);
 
-    AssertFatal (thread_id < itti_desc.thread_max, "Thread id (%d) is out of range (%d)\n", thread_id, itti_desc.thread_max);
+    AssertFatal (thread_id < itti_desc.thread_max, "Thread id (%d) is out of range (%d)!\n", thread_id, itti_desc.thread_max);
 
     /* Register the thread in itti dump */
     itti_dump_thread_use_ring_buffer();
@@ -853,7 +856,7 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
         ret = lfds611_queue_new(&itti_desc.tasks[task_id].message_queue, itti_desc.tasks_info[task_id].queue_size);
         if (ret < 0)
         {
-            AssertFatal (0, "lfds611_queue_new failed for task %s\n", itti_get_task_name(task_id));
+            AssertFatal (0, "lfds611_queue_new failed for task %s!\n", itti_get_task_name(task_id));
         }
     }
 
@@ -865,7 +868,7 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
         itti_desc.threads[thread_id].epoll_fd = epoll_create1(0);
         if (itti_desc.threads[thread_id].epoll_fd == -1) {
             /* Always assert on this condition */
-            AssertFatal (0, "Failed to create new epoll fd: %s\n", strerror(errno));
+            AssertFatal (0, "Failed to create new epoll fd: %s!\n", strerror(errno));
         }
 
 # if defined(KERNEL_VERSION_PRE_2_6_30)
@@ -879,7 +882,7 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
         if (itti_desc.threads[thread_id].task_event_fd == -1)
         {
             /* Always assert on this condition */
-            AssertFatal (0, " eventfd failed: %s\n", strerror(errno));
+            AssertFatal (0, " eventfd failed: %s!\n", strerror(errno));
         }
 
         itti_desc.threads[thread_id].nb_events = 1;
@@ -894,7 +897,7 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
             itti_desc.threads[thread_id].task_event_fd, itti_desc.threads[thread_id].events) != 0)
         {
             /* Always assert on this condition */
-            AssertFatal (0, " epoll_ctl (EPOLL_CTL_ADD) failed: %s\n", strerror(errno));
+            AssertFatal (0, " epoll_ctl (EPOLL_CTL_ADD) failed: %s!\n", strerror(errno));
         }
 
         ITTI_DEBUG(ITTI_DEBUG_EVEN_FD, " Successfully subscribed fd %d for thread %d\n",
diff --git a/common/utils/itti/intertask_interface.h b/common/utils/itti/intertask_interface.h
index 56f3ac428c1..1d1e18298b8 100644
--- a/common/utils/itti/intertask_interface.h
+++ b/common/utils/itti/intertask_interface.h
@@ -232,7 +232,7 @@ void itti_send_terminate_message(task_id_t task_id);
 
 void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize_t size);
 
-void itti_free(task_id_t task_id, void *ptr);
+int itti_free(task_id_t task_id, void *ptr);
 
 #endif /* INTERTASK_INTERFACE_H_ */
 /* @} */
diff --git a/common/utils/itti/intertask_interface_dump.c b/common/utils/itti/intertask_interface_dump.c
index 01e6fdb8f9f..8d434d61fdb 100644
--- a/common/utils/itti/intertask_interface_dump.c
+++ b/common/utils/itti/intertask_interface_dump.c
@@ -69,14 +69,12 @@ static const int itti_dump_debug = 0; // 0x8 | 0x4 | 0x2;
 #ifdef RTAI
 # define ITTI_DUMP_DEBUG(m, x, args...) do { if ((m) & itti_dump_debug) rt_printk("[ITTI_DUMP][D]"x, ##args); } \
     while(0)
-# define ITTI_DUMP_ERROR(x, args...) do { rt_printk("[ITTI_DUMP][E]"x, ##args); } \
-    while(0)
 #else
 # define ITTI_DUMP_DEBUG(m, x, args...) do { if ((m) & itti_dump_debug) fprintf(stdout, "[ITTI_DUMP][D]"x, ##args); } \
     while(0)
-# define ITTI_DUMP_ERROR(x, args...) do { fprintf(stdout, "[ITTI_DUMP][E]"x, ##args); } \
-    while(0)
 #endif
+#define ITTI_DUMP_ERROR(x, args...) do { fprintf(stdout, "[ITTI_DUMP][E]"x, ##args); } \
+    while(0)
 
 #ifndef EFD_SEMAPHORE
 # define KERNEL_VERSION_PRE_2_6_30 1
@@ -165,11 +163,11 @@ static int itti_dump_send_message(int sd, itti_dump_queue_item_t *message)
     /* Allocate memory for message header and payload */
     size_t size = sizeof(itti_dump_message_t) + message->data_size;
 
-    AssertFatal (sd > 0, "Socket descriptor (%d) is invalid\n", sd);
-    AssertFatal (message != NULL, "Message is NULL\n");
+    AssertFatal (sd > 0, "Socket descriptor (%d) is invalid!\n", sd);
+    AssertFatal (message != NULL, "Message is NULL!\n");
 
     new_message = calloc(1, size);
-    AssertFatal (new_message != NULL, "New message allocation failed\n");
+    AssertFatal (new_message != NULL, "New message allocation failed!\n");
 
     /* Preparing the header */
     new_message->header.message_size = size;
@@ -228,8 +226,8 @@ static int itti_dump_send_xml_definition(const int sd, const char *message_defin
     ssize_t bytes_sent = 0, total_sent = 0;
     uint8_t *data_ptr;
 
-    AssertFatal (sd > 0, "Socket descriptor (%d) is invalid\n", sd);
-    AssertFatal (message_definition_xml != NULL, "Message definition XML is NULL\n");
+    AssertFatal (sd > 0, "Socket descriptor (%d) is invalid!\n", sd);
+    AssertFatal (message_definition_xml != NULL, "Message definition XML is NULL!\n");
 
     itti_dump_message_size = sizeof(itti_socket_header_t) + message_definition_xml_length;
 
@@ -289,7 +287,7 @@ static int itti_dump_enqueue_message(itti_dump_queue_item_t *new, uint32_t messa
 {
     struct lfds611_freelist_element *new_queue_element = NULL;
     int overwrite_flag;
-    AssertFatal (new != NULL, "Message to queue is NULL\n");
+    AssertFatal (new != NULL, "Message to queue is NULL!\n");
 
 #if defined(OAI_EMU) || defined(RTAI)
     vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_DUMP_ENQUEUE_MESSAGE, VCD_FUNCTION_IN);
@@ -324,7 +322,7 @@ static int itti_dump_enqueue_message(itti_dump_queue_item_t *new, uint32_t messa
 
             /* Call to write for an event fd must be of 8 bytes */
             write_ret = write(itti_dump_queue.event_fd, &sem_counter, sizeof(sem_counter));
-            AssertFatal (write_ret == sizeof(sem_counter), "Write to dump event failed (%ld/%ld)\n",  write_ret, sizeof(sem_counter));
+            AssertFatal (write_ret == sizeof(sem_counter), "Write to dump event failed (%d/%d)!\n", (int) write_ret, (int) sizeof(sem_counter));
         }
 #endif
         __sync_fetch_and_add (&pending_messages, 1);
@@ -405,7 +403,7 @@ static int itti_dump_flush_ring_buffer(int flush_all)
                 }
                 else
                 {
-                    AssertFatal (0, "Dump event with no data\n");
+                    AssertFatal (0, "Dump event with no data!\n");
                 }
             }
             else
@@ -462,13 +460,13 @@ static int itti_dump_handle_new_connection(int sd, const char *xml_definition, u
 
         ITTI_DUMP_DEBUG(0x2, " Found place to store new connection: %d\n", i);
 
-        AssertFatal (i < ITTI_DUMP_MAX_CON, "No more connection available (%d/%d) for socked %d\n", i, ITTI_DUMP_MAX_CON, sd);
+        AssertFatal (i < ITTI_DUMP_MAX_CON, "No more connection available (%d/%d) for socked %d!\n", i, ITTI_DUMP_MAX_CON, sd);
 
         ITTI_DUMP_DEBUG(0x2, " Socket %d accepted\n", sd);
 
         /* Send the XML message definition */
         if (itti_dump_send_xml_definition(sd, xml_definition, xml_definition_length) < 0) {
-            AssertError (0, " Failed to send XML definition\n");
+            AssertError (0, {}, "Failed to send XML definition!\n");
             close (sd);
             return -1;
         }
@@ -505,7 +503,7 @@ static void *itti_dump_socket(void *arg_p)
     ITTI_DUMP_DEBUG(0x2, " Creating TCP dump socket on port %u\n", ITTI_PORT);
 
     message_definition_xml = (char *)arg_p;
-    AssertFatal (message_definition_xml != NULL, "Message definition XML is NULL\n");
+    AssertFatal (message_definition_xml != NULL, "Message definition XML is NULL!\n");
 
     message_definition_xml_length = strlen(message_definition_xml) + 1;
 
@@ -626,7 +624,7 @@ static void *itti_dump_socket(void *arg_p)
                         ITTI_DUMP_ERROR(" Failed read for semaphore: %s\n", strerror(errno));
                         pthread_exit(NULL);
                     }
-                    AssertFatal (read_ret == sizeof(sem_counter), "Failed to read from dump event FD (%ld/%ld)\n", read_ret, sizeof(sem_counter));
+                    AssertFatal (read_ret == sizeof(sem_counter), "Failed to read from dump event FD (%d/%d)!\n", (int) read_ret, (int) sizeof(sem_counter));
 #if defined(KERNEL_VERSION_PRE_2_6_30)
                     if (itti_dump_flush_ring_buffer(1) == 0)
 #else
@@ -644,7 +642,7 @@ static void *itti_dump_socket(void *arg_p)
                                 sem_counter = 1;
                                 /* Call to write for an event fd must be of 8 bytes */
                                 write_ret = write(itti_dump_queue.event_fd, &sem_counter, sizeof(sem_counter));
-                                AssertFatal (write_ret == sizeof(sem_counter), "Failed to write to dump event FD (%ld/%ld)\n", write_ret, sem_counter);
+                                AssertFatal (write_ret == sizeof(sem_counter), "Failed to write to dump event FD (%d/%d)!\n", (int) write_ret, (int) sem_counter);
                             }
 #endif
                         }
@@ -702,7 +700,7 @@ static void *itti_dump_socket(void *arg_p)
                     /* In case we don't find the matching sd in list of known
                      * connections -> assert.
                      */
-                    AssertFatal (j < ITTI_DUMP_MAX_CON, "Connection index not found (%d/%d) for socked %d\n", j, ITTI_DUMP_MAX_CON, i);
+                    AssertFatal (j < ITTI_DUMP_MAX_CON, "Connection index not found (%d/%d) for socked %d!\n", j, ITTI_DUMP_MAX_CON, i);
 
                     /* Re-initialize the socket to -1 so we can accept new
                      * incoming connections.
@@ -743,8 +741,8 @@ int itti_dump_queue_message(task_id_t sender_task,
         itti_dump_queue_item_t *new;
         size_t message_name_length;
 
-        AssertFatal (message_name != NULL, "Message name is NULL\n");
-        AssertFatal (message_p != NULL, "Message is NULL\n");
+        AssertFatal (message_name != NULL, "Message name is NULL!\n");
+        AssertFatal (message_p != NULL, "Message is NULL!\n");
 
 #if defined(OAI_EMU) || defined(RTAI)
         vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_DUMP_ENQUEUE_MESSAGE_MALLOC, VCD_FUNCTION_IN);
@@ -767,7 +765,7 @@ int itti_dump_queue_message(task_id_t sender_task,
         new->message_number  = message_number;
 
         message_name_length = strlen(message_name) + 1;
-        AssertError (message_name_length <= SIGNAL_NAME_LENGTH, "Message name too long (%ld/%d)\n", message_name_length, SIGNAL_NAME_LENGTH);
+        AssertError (message_name_length <= SIGNAL_NAME_LENGTH, {}, "Message name too long (%d/%d)!\n", (int) message_name_length, SIGNAL_NAME_LENGTH);
         memcpy(new->message_name, message_name, message_name_length);
 
         itti_dump_enqueue_message(new, message_size, ITTI_DUMP_MESSAGE_TYPE);
@@ -823,7 +821,7 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons
                                NULL) != 1)
     {
         /* Always assert on this condition */
-        AssertFatal (0, " Failed to create ring buffer...\n");
+        AssertFatal (0, " Failed to create ring buffer!\n");
     }
 
 #ifdef RTAI
@@ -836,7 +834,7 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons
 # endif
     if (itti_dump_queue.event_fd == -1) {
         /* Always assert on this condition */
-        AssertFatal (0, "eventfd failed: %s\n", strerror(errno));
+        AssertFatal (0, "eventfd failed: %s!\n", strerror(errno));
     }
 #endif
 
@@ -850,22 +848,22 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons
     /* initialized with default attributes */
     ret = pthread_attr_init(&itti_dump_queue.attr);
     if (ret < 0) {
-        AssertFatal (0, "pthread_attr_init failed (%d:%s)\n", errno, strerror(errno));
+        AssertFatal (0, "pthread_attr_init failed (%d:%s)!\n", errno, strerror(errno));
     }
 
     ret = pthread_attr_setschedpolicy(&itti_dump_queue.attr, SCHED_FIFO);
     if (ret < 0) {
-        AssertFatal (0, "pthread_attr_setschedpolicy (SCHED_IDLE) failed (%d:%s)\n", errno, strerror(errno));
+        AssertFatal (0, "pthread_attr_setschedpolicy (SCHED_IDLE) failed (%d:%s)!\n", errno, strerror(errno));
     }
     ret = pthread_attr_setschedparam(&itti_dump_queue.attr, &scheduler_param);
     if (ret < 0) {
-        AssertFatal (0, "pthread_attr_setschedparam failed (%d:%s)\n", errno, strerror(errno));
+        AssertFatal (0, "pthread_attr_setschedparam failed (%d:%s)!\n", errno, strerror(errno));
     }
 
     ret = pthread_create(&itti_dump_queue.itti_acceptor_thread, &itti_dump_queue.attr,
                          &itti_dump_socket, (void *)messages_definition_xml);
     if (ret < 0) {
-        AssertFatal (0, "pthread_create failed (%d:%s)\n", errno, strerror(errno));
+        AssertFatal (0, "pthread_create failed (%d:%s)!\n", errno, strerror(errno));
     }
 
     return 0;
diff --git a/common/utils/itti/memory_pools.c b/common/utils/itti/memory_pools.c
index d4ee2cd5709..120e200dee9 100644
--- a/common/utils/itti/memory_pools.c
+++ b/common/utils/itti/memory_pools.c
@@ -44,13 +44,9 @@ const static int mp_debug = 0;
 #ifdef RTAI
 # define MP_DEBUG(x, args...) do { if (mp_debug) rt_printk("[MP][D]"x, ##args); } \
     while(0)
-# define MP_ERROR(x, args...) do { rt_printk("[MP][E]"x, ##args); } \
-    while(0)
 #else
 # define MP_DEBUG(x, args...) do { if (mp_debug) fprintf(stdout, "[MP][D]"x, ##args); fflush (stdout); } \
     while(0)
-# define MP_ERROR(x, args...) do { fprintf(stdout, "[MP][E]"x, ##args); } \
-    while(0)
 #endif
 
 #if defined(OAI_EMU) || defined(RTAI)
@@ -221,7 +217,7 @@ static inline items_group_index_t items_group_get_free_item (items_group_t *item
     return (index);
 }
 
-static inline void items_group_put_free_item (items_group_t *items_group, items_group_index_t index)
+static inline int items_group_put_free_item (items_group_t *items_group, items_group_index_t index)
 {
     items_group_position_t  put_raw;
     items_group_position_t  put;
@@ -236,10 +232,12 @@ static inline void items_group_put_free_item (items_group_t *items_group, items_
         __sync_fetch_and_sub (&items_group->positions.ind.put, items_group->number_plus_one);
     }
 
-    AssertFatal (items_group->indexes[put] <= ITEMS_GROUP_INDEX_INVALID, "Index at current put position (%d) is not marked as free (%d)\n", put, items_group->number_plus_one);
+    AssertError (items_group->indexes[put] <= ITEMS_GROUP_INDEX_INVALID, return (EXIT_FAILURE),
+                 "Index at current put position (%d) is not marked as free (%d)!\n", put, items_group->number_plus_one);
 
     /* Save freed item index at current put position */
     items_group->indexes[put] = index;
+    return (EXIT_SUCCESS);
 }
 
 /*------------------------------------------------------------------------------*/
@@ -250,7 +248,8 @@ static inline memory_pools_t *memory_pools_from_handler (memory_pools_handle_t m
     /* Recover memory_pools */
     memory_pools = (memory_pools_t *) memory_pools_handle;
     /* Sanity check on passed handle */
-    AssertFatal (memory_pools->start_mark == POOLS_START_MARK, "Handle %p is not a valid memory pools handle, start mark is missing\n", memory_pools_handle);
+    AssertError (memory_pools->start_mark == POOLS_START_MARK, memory_pools = NULL,
+                 "Handle %p is not a valid memory pools handle, start mark is missing!\n", memory_pools_handle);
 
     return (memory_pools);
 }
@@ -265,7 +264,8 @@ static inline memory_pool_item_t *memory_pool_item_from_handler (memory_pool_ite
     memory_pool_item = (memory_pool_item_t *) address;
 
     /* Sanity check on passed handle */
-    AssertFatal (memory_pool_item->start.start_mark == POOL_ITEM_START_MARK, "Handle %p is not a valid memory pool item handle, start mark is missing\n", memory_pool_item);
+    AssertError (memory_pool_item->start.start_mark == POOL_ITEM_START_MARK, memory_pool_item = NULL,
+                 "Handle %p is not a valid memory pool item handle, start mark is missing!\n", memory_pool_item);
 
     return (memory_pool_item);
 }
@@ -286,11 +286,11 @@ memory_pools_handle_t memory_pools_create (uint32_t pools_number)
     memory_pools_t *memory_pools;
     pool_id_t       pool;
 
-    AssertFatal (pools_number <= MAX_POOLS_NUMBER, "Too many memory pools requested (%d/%d)\n", pools_number, MAX_POOLS_NUMBER); /* Limit to a reasonable number of pools */
+    AssertFatal (pools_number <= MAX_POOLS_NUMBER, "Too many memory pools requested (%d/%d)!\n", pools_number, MAX_POOLS_NUMBER); /* Limit to a reasonable number of pools */
 
     /* Allocate memory_pools */
     memory_pools = malloc (sizeof(memory_pools_t));
-    AssertFatal (memory_pools != NULL, "Memory pools structure allocation failed\n");
+    AssertFatal (memory_pools != NULL, "Memory pools structure allocation failed!\n");
 
     /* Initialize memory_pools */
     {
@@ -300,7 +300,7 @@ memory_pools_handle_t memory_pools_create (uint32_t pools_number)
 
         /* Allocate pools */
         memory_pools->pools         = calloc (pools_number, sizeof(memory_pool_t));
-        AssertFatal (memory_pools->pools != NULL, "Memory pools allocation failed\n");
+        AssertFatal (memory_pools->pools != NULL, "Memory pools allocation failed!\n");
 
         /* Initialize pools */
         for (pool = 0; pool < pools_number; pool++)
@@ -325,6 +325,7 @@ char *memory_pools_statistics(memory_pools_handle_t memory_pools_handle)
 
     /* Recover memory_pools */
     memory_pools = memory_pools_from_handler (memory_pools_handle);
+    AssertFatal (memory_pools != NULL, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle);
 
     statistics = malloc(memory_pools->pools_defined * 200);
 
@@ -357,14 +358,15 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p
     items_group_index_t item_index;
     memory_pool_item_t *memory_pool_item;
 
-    AssertFatal (pool_items_number <= MAX_POOL_ITEMS_NUMBER, "Too many items for a memory pool (%u/%d)\n", pool_items_number, MAX_POOL_ITEMS_NUMBER); /* Limit to a reasonable number of items */
-    AssertFatal (pool_item_size <= MAX_POOL_ITEM_SIZE, "Item size is too big for memory pool items (%u/%d)\n", pool_item_size, MAX_POOL_ITEM_SIZE);   /* Limit to a reasonable item size */
+    AssertFatal (pool_items_number <= MAX_POOL_ITEMS_NUMBER, "Too many items for a memory pool (%u/%d)!\n", pool_items_number, MAX_POOL_ITEMS_NUMBER); /* Limit to a reasonable number of items */
+    AssertFatal (pool_item_size <= MAX_POOL_ITEM_SIZE, "Item size is too big for memory pool items (%u/%d)!\n", pool_item_size, MAX_POOL_ITEM_SIZE);   /* Limit to a reasonable item size */
 
     /* Recover memory_pools */
     memory_pools    = memory_pools_from_handler (memory_pools_handle);
+    AssertFatal (memory_pools != NULL, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle);
 
     /* Check number of already created pools */
-    AssertFatal (memory_pools->pools_defined < memory_pools->pools_number, "Can not allocate more memory pool (%d)\n", memory_pools->pools_number);
+    AssertFatal (memory_pools->pools_defined < memory_pools->pools_number, "Can not allocate more memory pool (%d)!\n", memory_pools->pools_number);
 
     /* Select pool */
     pool            = memory_pools->pools_defined;
@@ -383,7 +385,7 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p
 
         /* Allocate free indexes */
         memory_pool->items_group_free.indexes = malloc(memory_pool->items_group_free.number_plus_one * sizeof(items_group_index_t));
-        AssertFatal (memory_pool->items_group_free.indexes != NULL, "Memory pool indexes allocation failed\n");
+        AssertFatal (memory_pool->items_group_free.indexes != NULL, "Memory pool indexes allocation failed!\n");
 
         /* Initialize free indexes */
         for (item_index = 0; item_index < pool_items_number; item_index++)
@@ -395,7 +397,7 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p
 
         /* Allocate items */
         memory_pool->items = calloc (pool_items_number, memory_pool->pool_item_size);
-        AssertFatal (memory_pool->items != NULL, "Memory pool items allocation failed\n");
+        AssertFatal (memory_pool->items != NULL, "Memory pool items allocation failed!\n");
 
         /* Initialize items */
         for (item_index = 0; item_index < pool_items_number; item_index++)
@@ -428,6 +430,7 @@ memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_po
 
     /* Recover memory_pools */
     memory_pools = memory_pools_from_handler (memory_pools_handle);
+    AssertError (memory_pools != NULL, {}, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle);
 
     for (pool = 0; pool < memory_pools->pools_defined; pool++)
     {
@@ -455,7 +458,7 @@ memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_po
         /* Convert item index into memory_pool_item address */
         memory_pool_item                    = memory_pool_item_from_index (&memory_pools->pools[pool], item_index);
         /* Sanity check on item status, must be free */
-        AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_FREE, "Item status is not set to free (%d) in pool %u, item %d\n",
+        AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_FREE, "Item status is not set to free (%d) in pool %u, item %d!\n",
                      memory_pool_item->start.item_status, pool, item_index);
 
         memory_pool_item->start.item_status = ITEM_STATUS_ALLOCATED;
@@ -485,7 +488,7 @@ memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_po
     return memory_pool_item_handle;
 }
 
-void memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, uint16_t info_0)
+int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, uint16_t info_0)
 {
     memory_pools_t     *memory_pools;
     memory_pool_item_t *memory_pool_item;
@@ -494,11 +497,16 @@ void memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_i
     uint32_t            item_size;
     uint32_t            pool_item_size;
     uint16_t            info_1;
+    int                 result;
 
     /* Recover memory_pools */
     memory_pools = memory_pools_from_handler (memory_pools_handle);
+    AssertError (memory_pools != NULL, return (EXIT_FAILURE), "Failed to retrieve memory pools for handle %p!\n", memory_pools_handle);
+
     /* Recover memory pool item */
     memory_pool_item = memory_pool_item_from_handler (memory_pool_item_handle);
+    AssertError (memory_pool_item != NULL, return (EXIT_FAILURE), "Failed to retrieve memory pool item for handle %p!\n", memory_pool_item_handle);
+
     info_1 = memory_pool_item->start.info[1];
 
 #if defined(OAI_EMU) || defined(RTAI)
@@ -508,7 +516,7 @@ void memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_i
 
     /* Recover pool index */
     pool = memory_pool_item->start.pool_id;
-    AssertFatal (pool < memory_pools->pools_defined, "Pool index is invalid (%u/%u)\n", pool, memory_pools->pools_defined);
+    AssertFatal (pool < memory_pools->pools_defined, "Pool index is invalid (%u/%u)!\n", pool, memory_pools->pools_defined);
 
     item_size = memory_pools->pools[pool].item_data_number;
     pool_item_size = memory_pools->pools[pool].pool_item_size;
@@ -522,22 +530,29 @@ void memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_i
              memory_pools->pools[pool].items, ((uint32_t) (item_size * sizeof(memory_pool_data_t))));
 
     /* Sanity check on calculated item index */
-    AssertFatal (memory_pool_item == memory_pool_item_from_index(&memory_pools->pools[pool], item_index), "Incorrect memory pool item address (%p, %p) for pool %u, item %d\n",
+    AssertFatal (memory_pool_item == memory_pool_item_from_index(&memory_pools->pools[pool], item_index),
+                 "Incorrect memory pool item address (%p, %p) for pool %u, item %d!\n",
                  memory_pool_item, memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool, item_index);
     /* Sanity check on end marker, must still be present (no write overflow) */
-    AssertFatal (memory_pool_item->data[item_size] == POOL_ITEM_END_MARK, "Memory pool item is corrupted, end mark is not present for pool %u, item %d\n", pool, item_index);
+    AssertFatal (memory_pool_item->data[item_size] == POOL_ITEM_END_MARK,
+                 "Memory pool item is corrupted, end mark is not present for pool %u, item %d!\n", pool, item_index);
     /* Sanity check on item status, must be allocated */
-    AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_ALLOCATED, "Trying to free a non allocated (%x) memory pool item (pool %u, item %d)\n",
+    AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_ALLOCATED,
+                 "Trying to free a non allocated (%x) memory pool item (pool %u, item %d)!\n",
                  memory_pool_item->start.item_status, pool, item_index);
 
     memory_pool_item->start.item_status = ITEM_STATUS_FREE;
 
-    items_group_put_free_item(&memory_pools->pools[pool].items_group_free, item_index);
+    result = items_group_put_free_item(&memory_pools->pools[pool].items_group_free, item_index);
+
+    AssertError (result == EXIT_SUCCESS, {}, "Failed to free memory pool item (pool %u, item %d)!\n", pool, item_index);
 
 #if defined(OAI_EMU) || defined(RTAI)
     vcd_signal_dumper_dump_variable_by_name(VCD_SIGNAL_DUMPER_VARIABLE_MP_FREE,
                                             __sync_and_and_fetch (&vcd_mp_free, ~(1L << info_1)));
 #endif
+
+    return (result);
 }
 
 void memory_pools_set_info (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, int index, uint16_t info)
@@ -549,10 +564,11 @@ void memory_pools_set_info (memory_pools_handle_t memory_pools_handle, memory_po
     uint32_t            item_size;
     uint32_t            pool_item_size;
 
-    AssertFatal (index < MEMORY_POOL_ITEM_INFO_NUMBER, "Incorrect info index (%d/%d)\n", index, MEMORY_POOL_ITEM_INFO_NUMBER);
+    AssertFatal (index < MEMORY_POOL_ITEM_INFO_NUMBER, "Incorrect info index (%d/%d)!\n", index, MEMORY_POOL_ITEM_INFO_NUMBER);
 
     /* Recover memory pool item */
     memory_pool_item = memory_pool_item_from_handler (memory_pool_item_handle);
+    AssertFatal (memory_pool_item != NULL, "Failed to retrieve memory pool item for handle %p!\n", memory_pool_item_handle);
 
     /* Set info[1] */
     memory_pool_item->start.info[index] = info;
@@ -562,10 +578,11 @@ void memory_pools_set_info (memory_pools_handle_t memory_pools_handle, memory_po
     {
         /* Recover memory_pools */
         memory_pools = memory_pools_from_handler (memory_pools_handle);
+        AssertFatal (memory_pools != NULL, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle);
 
         /* Recover pool index */
         pool = memory_pool_item->start.pool_id;
-        AssertFatal (pool < memory_pools->pools_defined, "Pool index is invalid (%u/%u)\n", pool, memory_pools->pools_defined);
+        AssertFatal (pool < memory_pools->pools_defined, "Pool index is invalid (%u/%u)!\n", pool, memory_pools->pools_defined);
 
         item_size = memory_pools->pools[pool].item_data_number;
         pool_item_size = memory_pools->pools[pool].pool_item_size;
@@ -579,12 +596,15 @@ void memory_pools_set_info (memory_pools_handle_t memory_pools_handle, memory_po
                  memory_pools->pools[pool].items, ((uint32_t) (item_size * sizeof(memory_pool_data_t))));
 
         /* Sanity check on calculated item index */
-        AssertFatal (memory_pool_item == memory_pool_item_from_index(&memory_pools->pools[pool], item_index), "Incorrect memory pool item address (%p, %p) for pool %u, item %d\n",
+        AssertFatal (memory_pool_item == memory_pool_item_from_index(&memory_pools->pools[pool], item_index),
+                     "Incorrect memory pool item address (%p, %p) for pool %u, item %d!\n",
                      memory_pool_item, memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool, item_index);
         /* Sanity check on end marker, must still be present (no write overflow) */
-        AssertFatal (memory_pool_item->data[item_size] == POOL_ITEM_END_MARK, "Memory pool item is corrupted, end mark is not present for pool %u, item %d\n", pool, item_index);
+        AssertFatal (memory_pool_item->data[item_size] == POOL_ITEM_END_MARK,
+                     "Memory pool item is corrupted, end mark is not present for pool %u, item %d!\n", pool, item_index);
         /* Sanity check on item status, must be allocated */
-        AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_ALLOCATED, "Trying to free a non allocated (%x) memory pool item (pool %u, item %d)\n",
+        AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_ALLOCATED,
+                     "Trying to free a non allocated (%x) memory pool item (pool %u, item %d)\n",
                      memory_pool_item->start.item_status, pool, item_index);
     }
 }
diff --git a/common/utils/itti/memory_pools.h b/common/utils/itti/memory_pools.h
index eaea136a9a3..f5ba71d4b81 100644
--- a/common/utils/itti/memory_pools.h
+++ b/common/utils/itti/memory_pools.h
@@ -44,7 +44,7 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p
 
 memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_pools_handle, uint32_t item_size, uint16_t info_0, uint16_t info_1);
 
-void memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, uint16_t info_0);
+int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, uint16_t info_0);
 
 void memory_pools_set_info (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, int index, uint16_t info);
 
diff --git a/common/utils/itti/timer.c b/common/utils/itti/timer.c
index 299b401b402..8329ddeac2f 100644
--- a/common/utils/itti/timer.c
+++ b/common/utils/itti/timer.c
@@ -147,7 +147,7 @@ int timer_setup(
     if (timer_id == NULL) {
         return -1;
     }
-    AssertFatal (type < TIMER_TYPE_MAX, "Invalid timer type (%d/%d)\n", type, TIMER_TYPE_MAX);
+    AssertFatal (type < TIMER_TYPE_MAX, "Invalid timer type (%d/%d)!\n", type, TIMER_TYPE_MAX);
 
     /* Allocate new timer list element */
     timer_p = malloc(sizeof(struct timer_elm_s));
diff --git a/openair-cn/NAS/nas_ue_task.c b/openair-cn/NAS/nas_ue_task.c
index d4969f6db3e..f0654277882 100644
--- a/openair-cn/NAS/nas_ue_task.c
+++ b/openair-cn/NAS/nas_ue_task.c
@@ -29,6 +29,7 @@
 *******************************************************************************/
 
 #if defined(ENABLE_ITTI)
+# include "assertions.h"
 # include "intertask_interface.h"
 # include "nas_ue_task.h"
 # include "UTIL/LOG/log.h"
@@ -74,6 +75,7 @@ void *nas_ue_task(void *args_p) {
   const char           *msg_name;
   instance_t            instance;
   unsigned int          Mod_id;
+  int                   result;
 
   itti_mark_task_ready (TASK_NAS_UE);
 
@@ -167,7 +169,8 @@ void *nas_ue_task(void *args_p) {
             nas_proc_establish_cnf(NAS_CONN_ESTABLI_CNF (msg_p).nasMsg.data, NAS_CONN_ESTABLI_CNF (msg_p).nasMsg.length);
 
             /* TODO checks if NAS will free the nas message, better to do it there anyway! */
-            itti_free (ITTI_MSG_ORIGIN_ID(msg_p), NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.data);
+            result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.data);
+            AssertFatal (result == EXIT_SUCCESS, "Failed to free memory!\n");
           }
           break;
 
@@ -196,7 +199,8 @@ void *nas_ue_task(void *args_p) {
           nas_proc_dl_transfer_ind (NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data, NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length);
 
           /* TODO checks if NAS will free the nas message, better to do it there anyway! */
-          itti_free (ITTI_MSG_ORIGIN_ID(msg_p), NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data);
+          result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data);
+          AssertFatal (result == EXIT_SUCCESS, "Failed to free memory!\n");
           break;
 
         default:
-- 
GitLab