LCOV - code coverage report
Current view: top level - libs/mem/src - mem_delete.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 92.6 % 27 25
Test Date: 2026-01-12 05:34:38 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #include "mem.h"
       2              : 
       3         2871 : Return memory_delete(memory *memory_structure)
       4              : {
       5              :         /** Return status
       6              :          *  The status that will be passed to return() before exiting
       7              :          *  By default, the function worked without errors
       8              :          */
       9         2871 :         Return status = SUCCESS;
      10              : 
      11         2871 :         if(memory_structure == NULL)
      12              :         {
      13            0 :                 slog(ERROR,"Memory management; Descriptor is NULL");
      14            0 :                 status = FAILURE;
      15              :         }
      16              : 
      17         2871 :         if(SUCCESS == status)
      18              :         {
      19         2871 :                 const size_t previously_allocated = memory_structure->actually_allocated_bytes;
      20         2871 :                 size_t previous_effective_bytes = 0;
      21         2871 :                 size_t previous_alignment_overhead = 0;
      22              : 
      23         2871 :                 run(memory_guarded_size(memory_structure->element_size,
      24              :                         memory_structure->length,
      25              :                         &previous_effective_bytes));
      26              : 
      27         2871 :                 if(previously_allocated > previous_effective_bytes)
      28              :                 {
      29         1191 :                         previous_alignment_overhead = previously_allocated - previous_effective_bytes;
      30              :                 }
      31              : 
      32         2871 :                 if(memory_structure->data != NULL)
      33              :                 {
      34         1268 :                         free(memory_structure->data);
      35              : 
      36         1268 :                         if(previously_allocated > 0)
      37              :                         {
      38         1268 :                                 telemetry_reduce(previously_allocated);
      39         1268 :                                 telemetry_free_total_bytes(previously_allocated);
      40              :                         }
      41              : 
      42         1268 :                         telemetry_free_counter();
      43         1268 :                         telemetry_active_descriptor_release();
      44              :                 }
      45              : 
      46         2871 :                 if(previous_effective_bytes > 0)
      47              :                 {
      48         1268 :                         telemetry_effective_reduce(previous_effective_bytes);
      49              :                 }
      50              : 
      51         2871 :                 if(previous_alignment_overhead > 0)
      52              :                 {
      53         1191 :                         telemetry_alignment_overhead_reduce(previous_alignment_overhead);
      54              :                 }
      55              : 
      56         2871 :                 memory_structure->data = NULL;
      57         2871 :                 memory_structure->length = 0;
      58         2871 :                 memory_structure->actually_allocated_bytes = 0;
      59              :         }
      60              : 
      61         2871 :         provide(status);
      62              : }
        

Generated by: LCOV version 2.0-1