Changeset d08c691


Ignore:
Timestamp:
07/27/10 17:05:51 (10 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
8608a0fa
Parents:
c69b593
Message:
  • Actually check the return value of posix_memalign
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/ior-peek.c

    r96bf151 rd08c691  
    104104        /* Is the current buffer big enough? */
    105105        if (DATA(io)->length < bytes_read) {
     106                int res = 0;
     107
    106108                if (DATA(io)->buffer)
    107109                        free(DATA(io)->buffer);
     
    109111                DATA(io)->offset = 0;
    110112#if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
    111                 /* We need to do this as read() of O_DIRECT might happen into this buffer.
    112                  * The docs suggest 512 bytes is all we need to align to, but I'm suspicious
    113                  * I expect disks with 4k blocks will arrive soon, and thus 4k is the minimum I'm
    114                  * willing to live with.
     113                /* We need to do this as read() of O_DIRECT might happen into
     114                 * this buffer.  The docs suggest 512 bytes is all we need to
     115                 * align to, but I'm suspicious. I expect disks with 4k blocks
     116                 * will arrive soon, and thus 4k is the minimum I'm willing to
     117                 * live with.
    115118                 */
    116                 posix_memalign(&DATA(io)->buffer, 4096, DATA(io)->length);
     119                res = posix_memalign((void **)&DATA(io)->buffer, 4096,
     120                                DATA(io)->length);
     121                if (res != 0) {
     122                        fprintf(stderr, "Error aligning IO buffer: %d\n",
     123                                        res);
     124                        return res;
     125                }
    117126#else
    118127                DATA(io)->buffer = malloc(DATA(io)->length);
     
    210219}
    211220
    212 static void *alignedrealloc(void *old, size_t oldsize, size_t size)
     221static void *alignedrealloc(void *old, size_t oldsize, size_t size, int *res)
    213222{
    214223#if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
     
    217226        if (size < oldsize)
    218227                return old;
    219         posix_memalign(&new, 4096, size);
     228        *res = posix_memalign(&new, 4096, size);
     229        if (*res != 0) {
     230                fprintf(stderr, "Error aligning IO buffer: %d\n", *res);
     231               
     232                return NULL;
     233        }
    220234        assert(oldsize<size);
    221235        memcpy(new,old,oldsize);
     
    231245{
    232246        off_t ret = 0;
     247        int res = 0;
    233248
    234249        /* Is there enough data in the buffer to serve this request? */
     
    238253                /* Round the read_amount up to the nearest MB */
    239254                read_amount += PEEK_SIZE - ((DATA(io)->length + read_amount) % PEEK_SIZE);
    240                 DATA(io)->buffer = alignedrealloc(DATA(io)->buffer, DATA(io)->length,
    241                         DATA(io)->length + read_amount);
     255                DATA(io)->buffer = alignedrealloc(DATA(io)->buffer,
     256                        DATA(io)->length,
     257                        DATA(io)->length + read_amount, &res);
     258
     259                if (DATA(io)->buffer == NULL) {
     260                        return res;     
     261                }
     262
    242263                /* Use the child reader to read more data into our managed
    243264                 * buffer */
Note: See TracChangeset for help on using the changeset viewer.