Changeset 89124ff


Ignore:
Timestamp:
Oct 25, 2019, 5:34:08 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
9bdb8b7
Parents:
eb5a115
Message:

add extra alignment check and missing frees

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.cfa

    reb5a115 r89124ff  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Oct 20 18:41:23 2019
    13 // Update Count     : 473
     12// Last Modified On : Tue Oct 22 08:57:52 2019
     13// Update Count     : 478
    1414//
    1515
     
    2121#include <string.h>                                                                             // memcpy, memset
    2222#include <malloc.h>                                                                             // malloc_usable_size
    23 #include <math.h>                                                                               // fabsf, fabs, fabsl
     23//#include <math.h>                                                                             // fabsf, fabs, fabsl
    2424#include <complex.h>                                                                    // _Complex_I
    2525#include <assert.h>
     
    4141                char * nptr;
    4242                size_t alignment = malloc_alignment( ptr );
    43                 if ( align != alignment ) {
     43                if ( align != alignment && (uintptr_t)ptr % align != 0 ) {
    4444                        size_t olen = malloc_usable_size( ptr );        // current allocation
    4545                        nptr = (char *)memalign( align, olen );
     
    4747                        size_t lnth = olen < nlen ? olen : nlen;        // min
    4848                        memcpy( nptr, ptr, lnth );                                      // initialize storage
     49                        free( ptr );
    4950                } else {
    5051                        nptr = (char *)ptr;
     
    6263                        size_t lnth = olen < nlen ? olen : nlen;        // min
    6364                        memcpy( nptr, ptr, lnth );                                      // initialize storage
     65                        free( ptr );
    6466                } else {
    6567                        nptr = (char *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc
Note: See TracChangeset for help on using the changeset viewer.