From 0bd46be2305ff8512002004bc202a27d777a322e Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sun, 7 Dec 2003 11:54:05 +0000 Subject: [PATCH] More small code/leak fixes --- ChangeLog | 2 +- TODO | 2 -- lib/crc.c | 33 +++++++++++---------------------- mbfido/postnetmail.c | 4 +++- mbfido/storenet.c | 6 +++--- 5 files changed, 18 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index f9fe59a5..1c362592 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,7 +20,7 @@ v0.39.3 26-Nov-2003 by valgrind. libcommon: - Code cleanup in proglock and pktname. + Code cleanup in proglock, pktname and crc. Fixed a forgotten fclose in proglock. libmsgbase: diff --git a/TODO b/TODO index 7c3e6388..f947bf81 100644 --- a/TODO +++ b/TODO @@ -117,8 +117,6 @@ mbfido: N: Tic, scan tests with valgrind. mbcico: - N: Test with valgrind, binkp, raw ifcico with tcp proto is ok. - N: Upgrade binkp protocol to 1.1. N: With binkp, if the other node is a binkp/1.0 mailer without MB diff --git a/lib/crc.c b/lib/crc.c index fc06cdac..18f79a06 100644 --- a/lib/crc.c +++ b/lib/crc.c @@ -1,11 +1,11 @@ /***************************************************************************** * + * $Id$ * File ..................: crc.c * Purpose ...............: Crc32 and Crc16 calculations - * Last modification date : 18-Mar-2000 * ***************************************************************************** - * Copyright (C) 1993-2000 + * Copyright (C) 1993-2003 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -188,7 +188,7 @@ unsigned long crc32ccitt(char *str, int l) unsigned long crc; for (crc = 0xffffffffL; l--; str++) - crc = crc32tab[((int) crc ^ (*str)) & 0xff] ^ ((crc >> 8) & 0x00ffffff); + crc = crc32tab[((int) crc ^ (*str)) & 0xff] ^ ((crc >> 8) & 0x00ffffffL); return crc; } @@ -216,7 +216,7 @@ unsigned long str_crc32(char *str) unsigned long crc; for (crc=0L; *str; str++) - crc = crc32tab[((int)crc^(*str)) & 0xff] ^ ((crc>>8) & 0x00ffffff); + crc = crc32tab[((int)crc^(*str)) & 0xff] ^ ((crc>>8) & 0x00ffffffL); return crc; } @@ -226,24 +226,13 @@ unsigned long StringCRC32(char *str) { unsigned long crc; - for (crc = 0xffffffff; *str; str++) - crc = crc32tab[((int)crc^(*str)) & 0xff] ^ ((crc>>8) & 0x00ffffff); + for (crc = 0xffffffffL; *str; str++) + crc = crc32tab[((int)crc^(*str)) & 0xff] ^ ((crc>>8) & 0x00ffffffL); return crc; } -/* - * Update CRC32, first initialize CRC with 0xffffffff. - */ -/* -unsigned long update_crc32(int octet, unsigned long crc) -{ - return (crc32tab[((int)crc ^ ((long)octet)) & 0xff] ^ ((((unsigned long)crc) >> 8) & 0x00ffffff)); -} -*/ - - /* * Update CRC32, first initialize crc with 0xffffffff */ @@ -254,7 +243,7 @@ unsigned long upd_crc32(char *buf, unsigned long crc, int len) cr = crc; for (i = 0; i < len; i++) { - cr = (crc32tab[((int)cr ^ ((long)buf[i])) & 0xff] ^ ((((unsigned long)cr) >> 8) & 0x00ffffff)); + cr = (crc32tab[((int)cr ^ ((long)buf[i])) & 0xff] ^ ((((unsigned long)cr) >> 8) & 0x00ffffffL)); } return cr; } @@ -269,13 +258,13 @@ unsigned long norm_crc32(unsigned long crc) { unsigned long L; - L = crc & 0x000000ff; + L = crc & 0x000000ffL; L <<= 8; - L |= ((crc >> 8) & 0x000000ff); + L |= ((crc >> 8) & 0x000000ffL); L <<= 8; - L |= ((crc >> 16) & 0x000000ff); + L |= ((crc >> 16) & 0x000000ffL); L <<= 8; - L |= ((crc >> 24) & 0x000000ff); + L |= ((crc >> 24) & 0x000000ffL); return L; } diff --git a/mbfido/postnetmail.c b/mbfido/postnetmail.c index 8cb0c0d8..75e038cc 100644 --- a/mbfido/postnetmail.c +++ b/mbfido/postnetmail.c @@ -125,7 +125,9 @@ int postnetmail(FILE *fp, faddr *f, faddr *t, char *orig, char *subject, time_t } tidy_faddr(ta); } - free(msgid); + if (msgid) + free(msgid); + msgid = NULL; } if (!strncmp(buf, "\001FMPT", 5)) { p = strtok(buf, " \n"); diff --git a/mbfido/storenet.c b/mbfido/storenet.c index c3fa53ff..d32ce44f 100644 --- a/mbfido/storenet.c +++ b/mbfido/storenet.c @@ -4,7 +4,7 @@ * Purpose ...............: Import a netmail message in the message base. * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2003 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -133,11 +133,11 @@ int storenet(faddr *f, faddr *t, time_t mdate, int flags, char *Subj, char *msgi * Set MSGID and REPLY crc. */ if (msgid != NULL) { - crc2 = -1; + crc2 = 0xffffffffL; Msg.MsgIdCRC = upd_crc32(msgid, crc2, strlen(msgid)); } if (reply != NULL) { - crc2 = -1; + crc2 = 0xffffffffL; Msg.ReplyCRC = upd_crc32(reply, crc2, strlen(reply)); }