Changeset 112 in svn for branches/1.0/mem.c


Ignore:
Timestamp:
2006-08-29T13:11:42+02:00 (9 years ago)
Author:
Xuefer
Message:

avoid crash when OOM on mem_(calloc|realloc|strndup)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.0/mem.c

    r54 r112  
    242242    void *p = xc_mem_malloc(mem, realsize);
    243243
    244     memset(p, 0, realsize);
     244    if (p) {
     245        memset(p, 0, realsize);
     246    }
    245247    return p;
    246248}
     
    249251{
    250252    void *newp = xc_mem_malloc(mem, size);
    251     memcpy(newp, p, size);
    252     xc_mem_free(mem, p);
     253    if (p) {
     254        memcpy(newp, p, size);
     255        xc_mem_free(mem, p);
     256    }
    253257    return newp;
    254258}
     
    257261{
    258262    void *p = xc_mem_malloc(mem, len + 1);
    259     memcpy(p, str, len + 1);
     263    if (p) {
     264        memcpy(p, str, len + 1);
     265    }
    260266    return p;
    261267}
Note: See TracChangeset for help on using the changeset viewer.