Re: fixing memory leaks before the pretest

From:

Ted Zlatanov

Subject:

Re: fixing memory leaks before the pretest

Date:

Mon, 09 Jan 2012 19:59:22 -0500

User-agent:

Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux)

On Sat, 07 Jan 2012 23:49:01 +0800 Chong Yidong <address@hidden> wrote:
CY> Ted Zlatanov <address@hidden> writes:
>> I am seeing memory growth on GNU/Linux with Gnus and GnuTLS that I
>> don't see otherwise without Gnus, so it's faintly possible GnuTLS is
>> not the determining factor. I have gone over the gnutls.c code and
>> don't see where the GnuTLS glue could be leaking.
CY> Do you have a test case for, e.g. creating and closing a few thousand
CY> GnuTLS connections to a localhost running apache with https and seeing
CY> if there is any memory impact? That would be the first thing I would
CY> try, but I haven't had the time to look into this.
I did, to a Dovecot IMAP server:
#+begin_src lisp
(require 'gnutls)
(setq gnutls-log-level 10)
(dotimes (n 10000)
(setq buf (open-gnutls-stream "tls" "tls-buffer" "myserver" "imaps"))
(delete-process buf))
#+end_src
It took a while, but throughout the memory usage remained consistently
at 331 MB virtual, 53 MB resident, 15 MB shared. Once the loop ended
and Emacs calmed down, virtual was the same but resident dropped to 39
MB and shared was 4 MB. By comparison a new Emacs without any GnuTLS
initialization is 320 MB virtual, 45 MB resident, and 14 MB shared.
Based on that, I don't think there are obvious GnuTLS leaks in the
connection open/close sequence. There may be leaks in the packet
handling, though. I tried:
#+begin_src lisp
(dotimes (n 10000)
(setq buf (open-gnutls-stream "tls" "tls-buffer" "myserver" "imaps"))
(process-send-string buf "hello there")
(sit-for 1)
(message (with-current-buffer (process-buffer buf) (buffer-string)))
(delete-process buf))
#+end_src
and did not see a difference in the memory usage either (331/53/10).
The IMAP server's greetings definitely came through, so the test was
exercising the connection. This does not necessarily mean there are no
leaks, but if they exist, they are probably not large or don't happen
with the first few packets exchanged.
I can look at this further... let me know what tests I should do. I'd
like to prove there are leaks at all.
Thanks
Ted