]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10167 contd
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 27 Mar 2017 16:10:18 +0000 (11:10 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 27 Mar 2017 16:10:22 +0000 (11:10 -0500)
libs/libks/src/ks_pool.c

index 490dcee5d69826d1175b5bb05f5dfbfcc6051bc4..7c1329ee9897480ac6b1dedbf5bab63cbf7f1213 100644 (file)
@@ -770,7 +770,7 @@ static int split_block(ks_pool_t *mp_p, void *free_addr, const unsigned long siz
  * error_p <- Pointer to ks_status_t which, if not NULL, will be set with
  * a ks_pool error code.
  */
-static void *get_space(ks_pool_t *mp_p, const unsigned long byte_size, ks_status_t *error_p)
+static void *get_space(ks_pool_t *mp_p, const unsigned long byte_size, unsigned long *padding, ks_status_t *error_p)
 {
        ks_pool_block_t *block_p;
        ks_pool_free_t free_pnt;
@@ -780,10 +780,16 @@ static void *get_space(ks_pool_t *mp_p, const unsigned long byte_size, ks_status
        void *free_addr = NULL, *free_end;
 
        size = byte_size;
+       *padding = 0;
+
        while ((size & (sizeof(void *) - 1)) > 0) {
                size++;
        }
 
+       if (size > byte_size) {
+               *padding = size - byte_size;
+       }
+
        /*
         * First we check the free lists looking for something with enough
         * pages.  Maybe we should only look X bits higher in the list.
@@ -929,7 +935,7 @@ static void *get_space(ks_pool_t *mp_p, const unsigned long byte_size, ks_status
  */
 static void *alloc_mem(ks_pool_t *mp_p, const unsigned long byte_size, ks_status_t *error_p)
 {
-       unsigned long size, fence;
+       unsigned long size, fence, padding = 0;
        void *addr;
        alloc_prefix_t *prefix;
 
@@ -943,7 +949,7 @@ static void *alloc_mem(ks_pool_t *mp_p, const unsigned long byte_size, ks_status
        fence = FENCE_SIZE;
 
        /* get our free space + the space for the fence post */
-       addr = get_space(mp_p, size + fence + PREFIX_SIZE, error_p);
+       addr = get_space(mp_p, size + fence + PREFIX_SIZE, &padding, error_p);
        if (addr == NULL) {
                /* error_p set in get_space */
                return NULL;
@@ -953,7 +959,7 @@ static void *alloc_mem(ks_pool_t *mp_p, const unsigned long byte_size, ks_status
        prefix = (alloc_prefix_t *) addr;
        prefix->m1 = PRE_MAGIC1;
        prefix->m2 = PRE_MAGIC2;
-       prefix->size = size + fence + PREFIX_SIZE;
+       prefix->size = size + fence + PREFIX_SIZE + padding;
        prefix->refs = 1;
 
        if (mp_p->mp_log_func != NULL) {