Changeset bbda5ab in mainline for uspace/lib/c/generic/sysinfo.c


Ignore:
Timestamp:
2010-04-18T12:15:18Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e1b6742
Parents:
3d482e0
Message:

use realloc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/sysinfo.c

    r3d482e0 rbbda5ab  
    103103           in common cases. */
    104104       
     105        void *data = NULL;
     106       
    105107        while (true) {
    106108                /* Get the binary data size */
    107109                int ret = sysinfo_get_data_size(path, size);
    108                 if (ret != EOK) {
    109                         /* Not binary data item */
    110                         return NULL;
     110                if ((ret != EOK) || (size == 0)) {
     111                        /* Not a binary data item
     112                           or an empty item */
     113                        break;
    111114                }
    112115               
    113                 void *data = malloc(*size);
     116                data = realloc(data, *size);
    114117                if (data == NULL)
    115                         return NULL;
     118                        break;
    116119               
    117120                /* Get the data */
     
    121124                        return data;
    122125               
    123                 /* Dispose the buffer */
    124                 free(data);
    125                
    126126                if (ret != ENOMEM) {
    127127                        /* The failure to get the data was not caused
    128128                           by wrong buffer size */
    129                         return NULL;
     129                        break;
    130130                }
    131131        }
     132       
     133        if (data != NULL)
     134                free(data);
     135       
     136        *size = 0;
     137        return NULL;
    132138}
    133139
Note: See TracChangeset for help on using the changeset viewer.