You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2007/06/25 18:28:51 UTC
svn commit: r550538 - in /spamassassin/trunk/spamc: libspamc.c libspamc.h
Author: jm
Date: Mon Jun 25 09:28:50 2007
New Revision: 550538
URL: http://svn.apache.org/viewvc?view=rev&rev=550538
Log:
bug 5531: transport_setup() leaks a small amount of memory each time it's called; fix, by adding a API for SA 3.3.0, transport_cleanup()
Modified:
spamassassin/trunk/spamc/libspamc.c
spamassassin/trunk/spamc/libspamc.h
Modified: spamassassin/trunk/spamc/libspamc.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/spamc/libspamc.c?view=diff&rev=550538&r1=550537&r2=550538
==============================================================================
--- spamassassin/trunk/spamc/libspamc.c (original)
+++ spamassassin/trunk/spamc/libspamc.c Mon Jun 25 09:28:50 2007
@@ -581,12 +581,6 @@
sleep(retry_sleep);
} /* for(numloops...) */
-#ifdef SPAMC_HAS_ADDRINFO
- for(numloops=0;numloops<tp->nhosts;numloops++) {
- freeaddrinfo(tp->hosts[numloops]);
- }
-#endif
-
libspamc_log(tp->flags, LOG_ERR,
"connection attempt to spamd aborted after %d retries",
connect_retries);
@@ -1761,7 +1755,6 @@
while (rnum-- > 0) {
tmp = tp->hosts[0];
- /* TODO: free using freeaddrinfo() */
for (i = 1; i < tp->nhosts; i++)
tp->hosts[i - 1] = tp->hosts[i];
@@ -2016,6 +2009,29 @@
/* oops, unknown transport type */
return EX_OSERR;
+}
+
+/*
+* transport_cleanup()
+*
+* Given a "transport" object that says how we're to connect to the
+* spam daemon, delete and free any buffers allocated so that it
+* can be discarded without causing a memory leak.
+*/
+void transport_cleanup(struct transport *tp)
+{
+
+#ifdef SPAMC_HAS_ADDRINFO
+ int i;
+
+ for(i=0;i<tp->nhosts;i++) {
+ if (tp->hosts[i] != NULL) {
+ freeaddrinfo(tp->hosts[i]);
+ tp->hosts[i] = NULL;
+ }
+ }
+#endif
+
}
/* --------------------------------------------------------------------------- */
Modified: spamassassin/trunk/spamc/libspamc.h
URL: http://svn.apache.org/viewvc/spamassassin/trunk/spamc/libspamc.h?view=diff&rev=550538&r1=550537&r2=550538
==============================================================================
--- spamassassin/trunk/spamc/libspamc.h (original)
+++ spamassassin/trunk/spamc/libspamc.h Mon Jun 25 09:28:50 2007
@@ -235,6 +235,10 @@
int retry_sleep;
};
+/* Initialise and setup transport-specific context for the connection
+ * to spamd. Note that this may leak a small amount of string data for
+ * the remote hostname (bug 5531) if called repeatedly; use
+ * transport_cleanup() to clean this up. */
extern void transport_init(struct transport *tp);
extern int transport_setup(struct transport *tp, int flags);
@@ -290,5 +294,13 @@
const int check_only, const int safe_fallback);
void libspamc_log(int flags, int level, char *msg, ...);
+
+/* Cleanup the resources allocated for storing details of the transport.
+ * Added in SpamAssassin 3.3.0. */
+void transport_cleanup(struct transport *tp);
+
+/* define a preprocessor symbol so that calling code can tell if the
+ * transport_cleanup() API function is available. */
+#define SPAMC_HAS_TRANSPORT_CLEANUP
#endif