[tpop3d-discuss] memory leak fixing in 1.5.1
Kevin Bonner
keb at pa.net
Wed, 27 Aug 2003 14:44:54 -0400
--Boundary-00=_mwPT/Cxa1ONdCQ9
Content-Type: Text/Plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Description: clearsigned data
Content-Disposition: inline
=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Testing with valgrind, I saw numerous memory leaks that needed fixing. I h=
ad=20
two tests, one where I just start the server and kill it, and one where I=20
start the server, do a successful connection, and disconnect.
Attached is a patch to resolve several of the memory leaks I saw. It is a=
=20
patch for the 1.5.1 source. I see that the CVS head has the SSL_CTX_free=20
call, but as ctx isn't referenced in the tls.c file, it probably won't be=20
able to find that reference.
Kevin Bonner
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE/TPwm/9i/ml3OBYMRAlegAKCgc35PdUEh6UEZrkuO8xmLlSKVlQCfb+SM
0jmjeyqsfu6sz9YR/qcu+F4=3D
=3DXl/A
=2D----END PGP SIGNATURE-----
--Boundary-00=_mwPT/Cxa1ONdCQ9
Content-Type: text/x-diff;
charset="us-ascii";
name="tpop3d-1.5.1-leak_fixes.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="tpop3d-1.5.1-leak_fixes.patch"
diff -urN tpop3d-1.5.1/auth_perl.c tpop3d-1.5.1.new/auth_perl.c
--- tpop3d-1.5.1/auth_perl.c Thu Jan 9 17:59:37 2003
+++ tpop3d-1.5.1.new/auth_perl.c Wed Aug 27 13:32:33 2003
@@ -98,7 +98,7 @@
}
/* Put a useful string into the environment. */
- putenv(xstrdup("TPOP3D_CONTEXT=auth_perl"));
+ setenv("TPOP3D_CONTEXT","auth_perl",1);
/* Create and start up perl interpreter. */
perl_interp = perl_alloc();
diff -urN tpop3d-1.5.1/connection.c tpop3d-1.5.1.new/connection.c
--- tpop3d-1.5.1/connection.c Mon Jul 14 19:31:20 2003
+++ tpop3d-1.5.1.new/connection.c Wed Aug 27 13:32:39 2003
@@ -319,6 +319,8 @@
pc = pop3command_new(p);
+ xfree(line);
+
return pc;
}
diff -urN tpop3d-1.5.1/listener.c tpop3d-1.5.1.new/listener.c
--- tpop3d-1.5.1/listener.c Thu Jan 9 17:59:37 2003
+++ tpop3d-1.5.1.new/listener.c Wed Aug 27 13:33:43 2003
@@ -182,6 +182,11 @@
regfree(&L->re);
xfree(L->regex);
#endif
+#ifdef USE_TLS
+ if (L->tls.ctx) {
+ tls_close(L->tls.ctx);
+ }
+#endif
xfree(L);
}
diff -urN tpop3d-1.5.1/maildir.c tpop3d-1.5.1.new/maildir.c
--- tpop3d-1.5.1/maildir.c Mon Jul 14 19:31:20 2003
+++ tpop3d-1.5.1.new/maildir.c Wed Aug 27 13:32:47 2003
@@ -113,6 +113,7 @@
lockdirname = xmalloc(strlen(dirname) + sizeof("/.poplock"));
sprintf(lockdirname, "%s/.poplock", dirname);
rmdir(lockdirname); /* Nothing we can do if this fails. */
+ xfree(lockdirname);
}
diff -urN tpop3d-1.5.1/main.c tpop3d-1.5.1.new/main.c
--- tpop3d-1.5.1/main.c Mon Jul 14 19:31:20 2003
+++ tpop3d-1.5.1.new/main.c Wed Aug 27 13:33:48 2003
@@ -310,6 +311,7 @@
skip:
xfree(host);
xfree(port);
+ xfree(domain);
#ifdef USE_TLS
xfree(cert);
xfree(pkey);
diff -urN tpop3d-1.5.1/tls.c tpop3d-1.5.1.new/tls.c
--- tpop3d-1.5.1/tls.c Thu Jan 9 17:59:39 2003
+++ tpop3d-1.5.1.new/tls.c Wed Aug 27 13:32:53 2003
@@ -113,8 +113,8 @@
/* tls_close:
* Shut down TLS stuff. */
-void tls_close(void) {
-
+void tls_close(SSL_CTX *ctx) {
+ SSL_CTX_free(ctx);
}
#endif /* USE_TLS */
diff -urN tpop3d-1.5.1/tls.h tpop3d-1.5.1.new/tls.h
--- tpop3d-1.5.1/tls.h Thu Jan 9 17:59:39 2003
+++ tpop3d-1.5.1.new/tls.h Wed Aug 27 10:29:29 2003
@@ -15,6 +15,6 @@
/* tls.c */
int tls_init(void);
SSL_CTX *tls_create_context(const char *certfile, const char *pkeyfile);
-void tls_close(void);
+void tls_close(SSL_CTX *ctx);
#endif /* __TLS_H_ */
--Boundary-00=_mwPT/Cxa1ONdCQ9--