Ignore:
Timestamp:
Feb 27, 2009, 5:08:07 AM (16 years ago)
Author:
bird
Message:

kash: malloc/free/friends gets a psh.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/shinstance.c

    r2289 r2290  
    169169{
    170170    memset(psh, 0, sizeof(*psh));
    171     free(psh);
     171    sh_free(NULL, psh);
    172172}
    173173
     
    190190
    191191   /* alloc clone array. */
    192    *dstp = dst = malloc(sizeof(*dst) * items + 1);
     192   *dstp = dst = sh_malloc(NULL, sizeof(*dst) * items + 1);
    193193   if (!dst)
    194194       return -1;
     
    198198   while (items-- > 0)
    199199   {
    200        dst[items] = strdup(src[items]);
     200       dst[items] = sh_strdup(NULL, src[items]);
    201201       if (!dst[items])
    202202       {
    203203           /* allocation error, clean up. */
    204204           while (dst[++items])
    205                free(dst[items]);
    206            free(dst);
     205               sh_free(NULL, dst[items]);
     206           sh_free(NULL, dst);
    207207           errno = ENOMEM;
    208208           return -1;
     
    231231     * The allocations.
    232232     */
    233     psh = calloc(sizeof(*psh), 1);
     233    psh = sh_calloc(NULL, sizeof(*psh), 1);
    234234    if (psh)
    235235    {
     
    344344
    345345    return ret;
     346}
     347
     348/** malloc() */
     349void *sh_malloc(shinstance *psh, size_t size)
     350{
     351    (void)psh;
     352    return malloc(size);
     353}
     354
     355/** calloc() */
     356void *sh_calloc(shinstance *psh, size_t num, size_t size)
     357{
     358    (void)psh;
     359    return calloc(num, size);
     360}
     361
     362/** realloc() */
     363void *sh_realloc(shinstance *psh, void *old, size_t new_size)
     364{
     365    return realloc(old, new_size);
     366}
     367
     368/** strdup() */
     369char *sh_strdup(shinstance *psh, const char *string)
     370{
     371    size_t len = strlen(string);
     372    char *ret = sh_malloc(psh, len + 1);
     373    if (ret)
     374        memcpy(ret, string, len + 1);
     375    return ret;
     376}
     377
     378/** free() */
     379void sh_free(shinstance *psh, void *ptr)
     380{
     381    if (ptr)
     382        free(ptr);
     383    (void)psh;
    346384}
    347385
Note: See TracChangeset for help on using the changeset viewer.