commit f0c7fdf008aeebfa039d76fc4e3e50dedc70170c
parent de1f9e1941a19ac9fbea4f18cfa8d7487b8e6d01
Author: Michael Elkins <me@mutt.org>
Date: Mon, 19 Nov 2001 19:41:14 +0000
added memory debugging code
fixed memory leak in free_list()
free memory associated with global settings on exit
Diffstat:
7 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/Makefile.am b/Makefile.am
@@ -1,5 +1,8 @@
bin_PROGRAMS=isync
isync_SOURCES=main.c imap.c sync.c maildir.c isync.h list.c cram.c config.c
+isync_LDADD=@DEBUGOBJ@
+isync_DEPENDENCIES=@DEBUGOBJ@
+EXTRA_isync_SOURCES=debug.c
man_MANS=isync.1
EXTRA_DIST=sample.isyncrc $(man_MANS)
INCLUDES=$(RPM_OPT_FLAGS)
diff --git a/TODO b/TODO
@@ -1,7 +1,5 @@
add support for syncing with other: and shared: via NAMESPACE
-finish implementing --quiet
-
--fast downloads the last message again if no new messages have arrived
isync gets confused when new mail is delivered while in the middle of an
diff --git a/config.c b/config.c
@@ -18,8 +18,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#define _GNU_SOURCE 1
-
#include <unistd.h>
#include <limits.h>
#include <errno.h>
@@ -39,16 +37,14 @@ config_defaults (config_t * conf)
memcpy (conf, &global, sizeof (config_t));
}
-#ifndef HAVE_STRNDUP
static char *
-strndup (const char *s, size_t nchars)
+my_strndup (const char *s, size_t nchars)
{
char *r = malloc (sizeof (char) * (nchars + 1));
strncpy (r, s, nchars);
r[nchars] = 0;
return r;
}
-#endif /* ! HAVE_STRNDUP */
char *
expand_strdup (const char *s)
@@ -73,7 +69,7 @@ expand_strdup (const char *s)
p = strchr (s, '/');
if (p)
{
- user = strndup (s, (int)(p - s));
+ user = my_strndup (s, (int)(p - s));
p++;
}
else
@@ -324,3 +320,12 @@ find_box (const char *s)
}
return 0;
}
+
+void
+free_config (void)
+{
+ free (global.user);
+ free (global.maildir);
+ free (global.host);
+ free (global.pass);
+}
diff --git a/configure.in b/configure.in
@@ -8,7 +8,13 @@ AC_ARG_WITH(ssl-dir, [ --with-ssl-dir=DIR location where openssl is insalled],
else
AC_MSG_ERROR(can't find OpenSSL in $withval)
fi])
-AC_CHECK_FUNCS(getopt_long strndup)
+AC_ARG_ENABLE(debug, [ --enable-debug enable memory debugging
+code],
+ [AC_DEFINE(DEBUG),
+ DEBUGOBJ=debug.o],
+ [DEBUGOBJ=''])
+AC_SUBST(DEBUGOBJ)
+AC_CHECK_FUNCS(getopt_long)
AC_CHECK_LIB(socket,socket)
AC_CHECK_LIB(nsl,inet_ntoa)
AC_CHECK_LIB(crypto,ERR_error_string)
diff --git a/isync.h b/isync.h
@@ -23,6 +23,7 @@
#if HAVE_LIBSSL
#include <openssl/ssl.h>
#endif
+#include "debug.h"
typedef struct
{
@@ -173,6 +174,7 @@ int sync_mailbox (mailbox_t *, imap_t *, int, unsigned int, unsigned int);
void load_config (const char *);
char * expand_strdup (const char *s);
config_t *find_box (const char *);
+void free_config (void);
void imap_close (imap_t *);
int imap_copy_message (imap_t * imap, unsigned int uid, const char *mailbox);
diff --git a/list.c b/list.c
@@ -153,7 +153,7 @@ free_list (list_t * list)
{
tmp = list;
list = list->next;
- if (is_list (list))
+ if (is_list (tmp))
free_list (tmp->child);
else if (is_atom (tmp))
free (tmp->val);
diff --git a/main.c b/main.c
@@ -334,5 +334,11 @@ cleanup:
/* gracefully close connection to the IMAP server */
imap_close (imap);
+ free_config ();
+
+#if DEBUG
+ debug_cleanup ();
+#endif
+
exit (0);
}