cURL / Mailing Lists / curl-library / Single Mail

curl-library

memory leak fei and small optimization for curl

From: <vadim_at_mbdsys.com>
Date: Sat, 17 Dec 2005 12:40:48 +0100

Hello,

I think i've stumbled on small memory leak for curl:
in file sendf.c:
=============================================================
int get_httpbodysize(char *buff)
{
    int i = 0;
    char *tmp = 0;

    while (*buff)
    {
        if (strnicmp("content-length:", buff, 15) == 0)
        {
            while (*buff && (*buff < '0' || *buff > '9'))
                buff++;

            for (i = 0; buff[i] && buff[i] >= '0' && buff[i] <= '9'; i++)
                ;

            tmp = strndup(buff, i); // TMP is NOT freed1111
            return atoi(tmp);
        }
        buff++;
    }

    return 0;
}
=======================================
I suggest to replace it by following code:
===================================================
int get_httpbodysize(char *buff)
{
    int i = 0;

    while (*buff)
    {
        if (strnicmp("content-length:", buff, 15) == 0)
        {
            buff += 15;

            /* do we really need this? the numeric value should follow
             * the header, possibly prefixed by white space, atoi
             * handle this by itself
             */
            while (*buff && (*buff < '0' || *buff > '9'))
                buff++;

            return atoi(buff);
        }
        buff++;
    }

    return 0;
}
==========================================================
Received on 2005-12-17