ip_frag: add IPv4 options fragment
[dpdk.git] / lib / eal / common / rte_malloc.c
index 9d39e58..7c67d21 100644 (file)
 #include <rte_memory.h>
 #include <rte_eal.h>
 #include <rte_eal_memconfig.h>
-#include <rte_branch_prediction.h>
-#include <rte_debug.h>
-#include <rte_launch.h>
-#include <rte_per_lcore.h>
-#include <rte_lcore.h>
 #include <rte_common.h>
 #include <rte_spinlock.h>
 
@@ -115,15 +110,22 @@ rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket)
 {
        void *ptr = rte_malloc_socket(type, size, align, socket);
 
+       if (ptr != NULL) {
+               struct malloc_elem *elem = malloc_elem_from_data(ptr);
+
+               if (elem->dirty) {
+                       memset(ptr, 0, size);
+               } else {
 #ifdef RTE_MALLOC_DEBUG
-       /*
-        * If DEBUG is enabled, then freed memory is marked with poison
-        * value and set to zero on allocation.
-        * If DEBUG is not enabled then  memory is already zeroed.
-        */
-       if (ptr != NULL)
-               memset(ptr, 0, size);
+                       /*
+                        * If DEBUG is enabled, then freed memory is marked
+                        * with a poison value and set to zero on allocation.
+                        * If DEBUG is disabled then memory is already zeroed.
+                        */
+                       memset(ptr, 0, size);
 #endif
+               }
+       }
 
        rte_eal_trace_mem_zmalloc(type, size, align, socket, ptr);
        return ptr;
@@ -162,6 +164,8 @@ rte_calloc(const char *type, size_t num, size_t size, unsigned align)
 void *
 rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket)
 {
+       size_t user_size;
+
        if (ptr == NULL)
                return rte_malloc_socket(NULL, size, align, socket);
 
@@ -171,6 +175,8 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket)
                return NULL;
        }
 
+       user_size = size;
+
        size = RTE_CACHE_LINE_ROUNDUP(size), align = RTE_CACHE_LINE_ROUNDUP(align);
 
        /* check requested socket id and alignment matches first, and if ok,
@@ -181,6 +187,9 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket)
                        RTE_PTR_ALIGN(ptr, align) == ptr &&
                        malloc_heap_resize(elem, size) == 0) {
                rte_eal_trace_mem_realloc(size, align, socket, ptr);
+
+               asan_set_redzone(elem, user_size);
+
                return ptr;
        }
 
@@ -192,7 +201,7 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket)
        if (new_ptr == NULL)
                return NULL;
        /* elem: |pad|data_elem|data|trailer| */
-       const size_t old_size = elem->size - elem->pad - MALLOC_ELEM_OVERHEAD;
+       const size_t old_size = old_malloc_size(elem);
        rte_memcpy(new_ptr, ptr, old_size < size ? old_size : size);
        rte_free(ptr);