Re: Memory leak suspicion in wap-appl.c

Vjacheslav Chekushin <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Organization LMT
Message-ID <[email protected]>
Hi,

Do you want to say that octstr_create_from_data doesn't allocate memory?
I don't think so.

lijl wrote:

> i think there is no memory leak.
> 
> 1.about set_refer_url()
>  sm->referer_url = octstr_duplicate(url);
> 2. about octstr.h
> #define octstr_duplicate(ostr) gw_claim_area(octstr_duplicate_real((ostr)))
> 3.about octstr.h
> Octstr *octstr_duplicate_real(Octstr *ostr)
> {
>     if (ostr == NULL)
>         return NULL;
>     seems_valid(ostr);
>     return octstr_create_from_data(ostr->data, ostr->len);
> }
> 
> 4.about octstr.h
> #define octstr_create_from_data(data, len)\
>     gw_claim_area(octstr_create_from_data_real((data), (len)))
> 5about octstr.h
> Octstr *octstr_create_from_data_real(const char *data, long len)
> {
>     Octstr *ostr;
> 
>     gw_assert(len >= 0);
>     if (data == NULL)
>         gw_assert(len == 0);
> 
>     ostr = gw_malloc(sizeof(*ostr));
>     if (len == 0) {
>         ostr->len = 0;
>         ostr->size = 0;
>         ostr->data = NULL;
>     } else {
>         ostr->len = len;
>         ostr->size = len + 1;
>         ostr->data = gw_malloc(ostr->size);


Allocate memory.

>         memcpy(ostr->data, data, len);
>         ostr->data[len] = '\0';
>     }
>     ostr->immutable = 0;
>     seems_valid(ostr);
>     return ostr;
> }
> 6about gwmem.h
> #define gw_claim_area(ptr) (gw_native_noop(ptr))
> 7about gwmem_native.c
> void *gw_native_noop(void *ptr) { return ptr; }
> this is memory allocated to url.
> 
> 
> ----------------------------------------------------------------


So after set_refer_url we get new allocated octstr that has
the only refernece: sm->referer_url

> 8. in  wap_app.c   function  return_reply()
> 
> octstr_destroy(url);          /* same as content.url */
> this is memory free.


Yes, url is destroyed, but sm->referer_url not.

-- 
Vjacheslav Chekushin                                mailto:[email protected]
Latvian Mobile Phone Company                        http://www.lmt.lv
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.