added memory debugging code

fixed memory leak in free_list()

free memory associated with global settings on exit
This commit is contained in:
Michael Elkins 2001-11-19 19:41:14 +00:00
parent de1f9e1941
commit f0c7fdf008
7 changed files with 30 additions and 10 deletions

View File

@ -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)

2
TODO
View File

@ -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

View File

@ -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);
}

View File

@ -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)

View File

@ -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);

2
list.c
View File

@ -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);

6
main.c
View File

@ -334,5 +334,11 @@ cleanup:
/* gracefully close connection to the IMAP server */
imap_close (imap);
free_config ();
#if DEBUG
debug_cleanup ();
#endif
exit (0);
}