[Asterisk-bsd] Memory leak in chan_capi

Hans Petter Selasky hselasky at c2i.net
Thu Aug 4 06:41:39 CDT 2005


Hi, 

I think there is a memory leak in chan_capi, if anyone is using it.

Memory is duplicated with strdup, but never freed. Solution: use alloca().

Here is a patch:

enum { max_telno = 256 }; /* including terminating zero */

static char *capi_number(u_int8_t *data, int strip, u_int8_t *buf) {
#define capi_number(data,strip) capi_number(data,strip,(u_int8_t 
*)alloca(max_telno))

   u_int16_t len;

   /* convert a CAPI structure into a 
    * zero terminated string 
    */
   if(data[0] == 0xFF)
   {
      len = data[1]|(data[2] << 8);
      data += 3;
   }
   else
   {
      len = data[0];
      data += 1;
   }

   if(len >= max_telno)
      len = max_telno-1;

   bcopy(data, buf, len);
   buf[len] = 0;

   return (char *)buf;
}

--HPS


More information about the Asterisk-BSD mailing list