From 86cc8e232dba748c3b058171b26e9e953b0e6a38 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Tue, 1 Jan 2008 17:52:46 -0500 Subject: [PATCH] Fixed a couple memory leaks. --- src/commands.c | 4 +++- src/mem.c | 6 +++++- src/pwmd.c | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/commands.c b/src/commands.c index 020f78ff..857d54c7 100644 --- a/src/commands.c +++ b/src/commands.c @@ -2280,14 +2280,16 @@ static void reset_notify(assuan_context_t ctx) static gpg_error_t parse_client_option(assuan_context_t ctx, const gchar *line) { gchar name[32] = {0}, value[256] = {0}; - pth_attr_t attr = pth_attr_of(pth_self()); if (sscanf(line, " %31[a-zA-Z] = %255c", name, value) != 2) return gpg_err_make(PWMD_ERR_SOURCE, GPG_ERR_SYNTAX); if (g_strcasecmp(name, (gchar *)"NAME") == 0) { + pth_attr_t attr = pth_attr_of(pth_self()); + log_write("OPTION CLIENT %s", line); pth_attr_set(attr, PTH_ATTR_NAME, value); + pth_attr_destroy(attr); } else return gpg_err_make(PWMD_ERR_SOURCE, GPG_ERR_UNKNOWN_OPTION); diff --git a/src/mem.c b/src/mem.c index 4ba4eb9a..2e48c3eb 100644 --- a/src/mem.c +++ b/src/mem.c @@ -33,6 +33,7 @@ #include "mem.h" static struct memlist_s *memlist; +static size_t allocations, deallocations; static struct memlist_s *memlist_remove(struct memlist_s *list, struct memlist_s *r) { @@ -45,6 +46,7 @@ static struct memlist_s *memlist_remove(struct memlist_s *list, struct memlist_s p = m->next; free(m); + deallocations++; if (last) { if (p) @@ -68,6 +70,7 @@ static struct memlist_s *memlist_remove(struct memlist_s *list, struct memlist_s static struct memlist_s *memlist_prepend(struct memlist_s *list, struct memlist_s *p) { + allocations++; p->next = list; return p; } @@ -218,5 +221,6 @@ void xdump(void) total += m->size; } - fprintf(stderr, "Total unfreed: %i bytes\n", total); + fprintf(stderr, "Total unfreed: %i bytes, allocations: %i, deallocations: %i\n", total, + allocations, deallocations); } diff --git a/src/pwmd.c b/src/pwmd.c index 913009ef..8b3586c7 100644 --- a/src/pwmd.c +++ b/src/pwmd.c @@ -148,6 +148,7 @@ void log_write(const gchar *fmt, ...) attr = pth_attr_of(pth_self()); pth_attr_get(attr, PTH_ATTR_NAME, &name); + pth_attr_destroy(attr); if (log_syslog == TRUE) syslog(LOG_INFO, "%s: %s", name, args); @@ -1265,6 +1266,7 @@ static void *socket_thread(void *arg) snprintf(buf, sizeof(buf), "%p", tid); attr = pth_attr_of(tid); pth_attr_set(attr, PTH_ATTR_NAME, buf); + pth_attr_destroy(attr); log_write(N_("new tid=%s, fd=%i"), buf, fd); new->fd = fd; new->tid = tid; @@ -1850,6 +1852,5 @@ do_exit: #if defined(DEBUG) && !defined(MEM_DEBUG) xdump(); #endif - xdump(); exit(estatus); } -- 2.11.4.GIT