Re: memory leak on dns failure?

Ming Fu <[email protected]>
Newsgroups gmane.comp.web.polipo.user
Message-ID <[email protected]>
OK find it.

The message atom eventually get retained before going to the function
httpClientRawErrorHeaders(), It is not released in the function, so here is
the diff against polipo-20080907
diff -c  http.c.back http.c
*** http.c.back 2009-04-23 14:40:02.000000000 -0400
--- http.c      2009-04-23 14:51:26.000000000 -0400
***************
*** 859,864 ****
--- 859,865 ----
          body = get_chunk();
          if(!body) {
              do_log(L_ERROR, "Couldn't allocate body buffer.\n");
+           releaseAtom(message);
              return -1;
          }
          m = snnprintf(body, 0, CHUNK_SIZE,
***************
*** 901,906 ****
--- 902,908 ----
          if(m <= 0 || m >= CHUNK_SIZE) {
              do_log(L_ERROR, "Couldn't write error body.\n");
              dispose_chunk(body);
+           releaseAtom(message);
              return -1;
          }
      } else {
***************
*** 914,919 ****
--- 916,923 ----
                   "\r\nDate: ",
                    code, atomString(message),
                    close ? "close" : "keep-alive");
+     releaseAtom(message);
+
      n = format_time(buf, n, size, current_time.tv_sec);
      if(code != 304) {
          n = snnprintf(buf, n, size,
***************
*** 923,929 ****
          if(etag)
              n = snnprintf(buf, n, size, "\r\nETag: \"%s\"", etag);
      }
!
      if(code != 304 && code != 412) {
          n = snnprintf(buf, n, size,
                        "\r\nExpires: 0"
--- 927,933 ----
          if(etag)
              n = snnprintf(buf, n, size, "\r\nETag: \"%s\"", etag);
      }
!
      if(code != 304 && code != 412) {
          n = snnprintf(buf, n, size,
                        "\r\nExpires: 0"


Does this sound reasonable?
Ming

On Thu, Apr 23, 2009 at 11:24 AM, Ming Fu <[email protected]> wrote:

> Woops, forget to paste in the kill -USR2 and the gdb afterwards.
>
> fed:polipo-20080907 1035$ kill -USR2 19698
> fed:polipo-20080907 1036$ gdb polipo 19698
> GNU gdb Red Hat Linux (6.6-45.fc8rh)
> Copyright (C) 2006 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you
> are
> welcome to change it and/or distribute copies of it under certain
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for details.
> This GDB was configured as "i386-redhat-linux-gnu"...
> Using host libthread_db library "/lib/libthread_db.so.1".
> Attaching to program: /home/fming/download/polipo-20080907/polipo, process
> 19698
> Reading symbols from /lib/libc.so.6...done.
> Loaded symbols for /lib/libc.so.6
> Reading symbols from /lib/ld-linux.so.2...done.
> Loaded symbols for /lib/ld-linux.so.2
> 0x00110416 in __kernel_vsyscall ()
> (gdb) break server.c:540
> Breakpoint 1 at 0x805ec3d: file server.c, line 540.
> Missing separate debuginfos, use: debuginfo-install glibc.i686
> (gdb) c
> Continuing.
> DNS: Host not found
> Host this.url.noexist lookup failed: Host not found (131072).
>
> Breakpoint 1, httpServerConnectionDnsHandler (status=-131072,
> request=0xbf9ee558)
>     at server.c:541
> 541             connection->connecting = 0;
> (gdb) print *message
> $1 = {refcount = 10, next = 0x0, length = 51, string = "H"}
> (gdb) print "%s\n", message->string
> $2 = "H"
> (gdb) printf "%s\n", message->string
> Host this.url.noexist lookup failed: Host not found
>
> On Thu, Apr 23, 2009 at 11:01 AM, Ming Fu <[email protected]> wrote:
>
>> Hi,
>>
>> I found the polipo grow bigger in memory footage upon bombed with url of
>> non-exist dns.
>> Each failed dns lookup will create an atom struct with the error message.
>> The reference count of the atom
>>
>> int
>>
>> httpServerConnectionDnsHandler(int status, GethostbynameRequestPtr request)
>> {
>>     HTTPConnectionPtr connection = request->data;
>>
>>     httpSetTimeout(connection, -1);
>>
>>     if(status <= 0) {
>>         AtomPtr message;
>>
>>
>>         message = internAtomF("Host %s lookup failed: %s",
>>                               request->name ?
>>                               request->name->string : "(unknown)",
>>                               request->error_message ?
>>
>>
>>                               request->error_message->string :
>>                               pstrerror(-status));
>>         do_log(L_ERROR, "Host %s lookup failed: %s (%d).\n",
>>                request->name ?
>>
>>
>>                scrub(request->name->string) : "(unknown)",
>>                request->error_message ?
>>                request->error_message->string :
>>                pstrerror(-status), -status);
>>
>>
>>         connection->connecting = 0;
>>         if(connection->server->request)
>>             httpServerAbortRequest(connection->server->request, 1, 504,
>>                                    retainAtom(message));
>>
>>
>>         httpServerAbort(connection, 1, 502, message);
>>         return 1;
>>     }
>>
>> Below are the gdb traces from polipo-20080907. I use wget to feed polipo
>> with url "this.url.noexist"
>>
>> # export http_proxy=127.0.0.1:7070
>> # wget this.url.noexist
>>
>> I feed it with the same bad url and see the atom reference count increase
>> every time.
>> I also tried to detach gdb from the polipo and send it a USR2 signal to
>> see if clean up the objects can free up the atom. It doesn't.
>> See the two gdb of the same process, and the kill -USR2 in between.
>>
>> Any in depth explanation of what does the httpServerAbortRequest() and
>> httpServerAbort() do will be helpful for me to track down the root of the
>> problem.
>>
>> Thanks
>> Ming
>>
>> (gdb) break server.c:540
>> Breakpoint 1 at 0x805ec3d: file server.c, line 540.
>> Missing separate debuginfos, use: debuginfo-install glibc.i686
>> (gdb) c
>> Continuing.
>> DNS: Host not found
>> Host this.url.noexist lookup failed: Host not found (131072).
>>
>> Breakpoint 1, httpServerConnectionDnsHandler (status=-131072,
>> request=0xbf9ee558)
>>     at server.c:541
>> 541             connection->connecting = 0;
>> (gdb) print *message
>> $1 = {refcount = 5, next = 0x0, length = 51, string = "H"}
>> (gdb) printf "%s", message.string
>> Host this.url.noexist lookup failed: Host not found(gdb)
>> (gdb) c
>> Host this.url.noexist lookup failed: Host not foundContinuing.
>> DNS: Host not found
>> Host this.url.noexist lookup failed: Host not found (131072).
>>
>> Breakpoint 1, httpServerConnectionDnsHandler (status=-131072,
>> request=0xbf9ee558)
>>     at server.c:541
>> 541             connection->connecting = 0;
>> (gdb) printf "%s", message.string
>> Host this.url.noexist lookup failed: Host not found(gdb) printf "%s",
>> message.string
>> (gdb) printf "%s", message.string
>> Host this.url.noexist lookup failed: Host not found(gdb)
>> Host tprintf "%s", message.string
>> Host this.url.noexist lookup failed: Host not found(gdb) c
>> Host this.url.noexist lookup failed: Host not foundContinuing.
>> DNS: Host not found
>> Host this.url.noexist lookup failed: Host not found (131072).
>>
>> Breakpoint 1, httpServerConnectionDnsHandler (status=-131072,
>> request=0xbf9ee558)
>>     at server.c:541
>> 541             connection->connecting = 0;
>> (gdb) print *message
>> $2 = {refcount = 7, next = 0x0, length = 51, string = "H"}
>> (gdb) printf "%s", message.string
>> Host this.url.noexist lookup failed: Host not found(gdb) c
>> Continuing.
>> DNS: Host not found
>> Host this.url.noexist lookup failed: Host not found (131072).
>>
>> Breakpoint 1, httpServerConnectionDnsHandler (status=-131072,
>> request=0xbf9ee558)
>>     at server.c:541
>> 541             connection->connecting = 0;
>> (gdb) print *message
>> $3 = {refcount = 8, next = 0x0, length = 51, string = "H"}
>> (gdb) printf "%s", message.string
>> Host this.url.noexist lookup failed: Host not found(gdb)
>> (gdb) c
>> Host this.url.noexist lookup failed: Host not foundContinuing.
>> DNS: Host not found
>> Host this.url.noexist lookup failed: Host not found (131072).
>>
>> Breakpoint 1, httpServerConnectionDnsHandler (status=-131072,
>> request=0xbf9ee558)
>>     at server.c:541
>> 541             connection->connecting = 0;
>> (gdb) print *message
>> $4 = {refcount = 9, next = 0x0, length = 51, string = "H"}
>> (gdb) printf "%s", message.string
>> Host this.url.noexist lookup failed: Host not found(gdb) c
>> Continuing.
>>
>>
>>
>>
>
------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
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.