database.c and config.c were responsible for the leaks...
committer: Markus Bröker <mbroeker@largo.homelinux.org>
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-mcbot (0.95-3) unstable; urgency=low
+mcbot (0.95-4) unstable; urgency=low
* Initial Release
* the location of mcbot.cgi is stored in the db
@@ -17,5 +17,7 @@
* IRC access without password added
* Help System was able to start a botwar. Fixed
* op, deop, kick, ban, unban, kickban implemented
+ * database.c: key=alloc(dbf, key); free(key.dptr) :) fixed
+ * only one memory hole is left: who can fix getpwnam in irc.c
- -- Markus Broeker <mbroeker@largo.homelinux.org> Mon, 11 Aug 2008 23:00:01 +0200
+ -- Markus Broeker <mbroeker@largo.homelinux.org> Mon, 11 Aug 2008 23:59:01 +0200
--- a/src/database.c
+++ b/src/database.c
@@ -66,7 +66,7 @@
GDBM_FILE dbf;
datum content;
datum key;
- static char msg[513];
+ static char msg[513] = { 0 };
if ((dbf = gdbm_open (file_name, 512, GDBM_READER, 0, 0)) == NULL)
return "db_lookup error";
@@ -75,9 +75,10 @@
key.dsize = strlen (entry) + 1;
content = gdbm_fetch (dbf, key);
- if (content.dptr != NULL)
+ if (content.dptr != NULL) {
snprintf (msg, 512, "%s", content.dptr);
- else
+ free (content.dptr);
+ } else
snprintf (msg, 512, "I haven't heard anything about %s.", entry);
gdbm_close (dbf);
@@ -87,9 +88,9 @@
char *db_elements (char *file_name)
{
GDBM_FILE dbf;
- datum key;
+ datum key, nextkey;
int count;
- static char msg[81];
+ static char msg[81] = { 0 };
if ((dbf = gdbm_open (file_name, 512, GDBM_READER, 0, 0)) == NULL)
return "db_lookup error";
@@ -98,7 +99,9 @@
count = 0;
while (key.dptr != NULL) {
- key = gdbm_nextkey (dbf, key);
+ nextkey = gdbm_nextkey (dbf, key);
+ free (key.dptr);
+ key = nextkey;
count++;
}
@@ -111,8 +114,8 @@
{
GDBM_FILE dbf;
datum content;
- datum key;
- static char msg[81];
+ datum key, nextkey;
+ static char msg[81] = { 0 };
int count;
if ((dbf = gdbm_open (file_name, 512, GDBM_READER, 0, 0)) == NULL)
@@ -121,11 +124,14 @@
key = gdbm_firstkey (dbf);
count = 0;
- while (key.dptr) {
+ while (key.dptr != NULL) {
content = gdbm_fetch (dbf, key);
printf ("%11s: %s\n", key.dptr, content.dptr);
- free (content.dptr);
- key = gdbm_nextkey (dbf, key);
+ if (content.dptr != NULL)
+ free (content.dptr);
+ nextkey = gdbm_nextkey (dbf, key);
+ free (key.dptr);
+ key = nextkey;
count++;
}
@@ -137,7 +143,7 @@
char *db_vaccuum (char *file_name)
{
GDBM_FILE dbf;
- static char msg[81];
+ static char msg[81] = { 0 };
if ((dbf = gdbm_open (file_name, 512, GDBM_WRITER, 0, 0)) == NULL)
return "db_vaccuum error";