Changeset 24324


Ignore:
Timestamp:
10/15/13 13:00:37 (9 years ago)
Author:
nit
Message:

[titan] fix possible memleak

File:
1 edited

Legend:

Unmodified
Added
Removed
  • titan/titan/global.h

    r24279 r24324  
    32553255        stream.avail_in = inlen;
    32563256        stream.next_in = (void*)inbuf;
    3257 
     3257 
    32583258        do
    32593259        {
     
    32683268                        return 1;
    32693269                }
    3270 
    32713270        }
    32723271        while(stream.avail_out == 0);
     3272       
     3273        char* tmpoutbuf = *outbuf;     
    32733274        *outlen = inlen - stream.avail_out;
    32743275        *outbuf = realloc(*outbuf, *outlen);
     3276        if(*outbuf == NULL) free(tmpoutbuf);   
    32753277
    32763278        (void)deflateEnd(&stream);
     
    33233325        stream.next_in = (void*)inbuf;
    33243326
     3327        int round = 0;
    33253328        do
    33263329        {
    33273330                stream.avail_out = maxbuf;
    3328                 stream.next_out = (void*)*outbuf;
     3331               
     3332                if(flag == 0 && round > 0)
     3333                {
     3334                        char* tmpoutbuf = *outbuf;
     3335                        *outbuf = realloc(*outbuf, maxbuf * (round + 1));
     3336                        if(*outbuf == NULL)
     3337                        {
     3338                                free(tmpoutbuf);
     3339                                (void)inflateEnd(&stream);
     3340                                return 1;
     3341                        }
     3342                        stream.next_out = (void*)(*outbuf) + maxbuf * round;
     3343                }
     3344                else
     3345                        stream.next_out = (void*)*outbuf;
    33293346
    33303347                ret = inflate(&stream, Z_NO_FLUSH);
     
    33403357                }
    33413358
     3359                round++;
    33423360        }
    33433361        while(stream.avail_out == 0);
    3344         *outlen = maxbuf - stream.avail_out;
    3345         if(flag == 0) *outbuf = realloc(*outbuf, *outlen);
     3362       
     3363        if(flag == 0)
     3364        {
     3365                char* tmpoutbuf = *outbuf;
     3366                *outlen = (maxbuf * round) - stream.avail_out;
     3367                *outbuf = realloc(*outbuf, *outlen);
     3368                if(*outbuf == NULL) free(tmpoutbuf);   
     3369        }
     3370        else
     3371                *outlen = maxbuf - stream.avail_out;                   
    33463372
    33473373        (void)inflateEnd(&stream);
Note: See TracChangeset for help on using the changeset viewer.