Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 6/7/83; site hao.UUCP Path: utzoo!watmath!clyde!floyd!harpo!seismo!hao!pag From: pag@hao.UUCP (Peter Gross) Newsgroups: net.news.b Subject: Bug fix for wasted memory use Message-ID: <899@hao.UUCP> Date: Thu, 29-Mar-84 12:49:28 EST Article-I.D.: hao.899 Posted: Thu Mar 29 12:49:28 1984 Date-Received: Fri, 30-Mar-84 02:43:12 EST Organization: High Altitude Obs./NCAR, Boulder CO Lines: 488 There is a problem with 2.10+ news' handling of unrecognized header fields that causes memory use to keep increasing. Certain notesfiles sites are adding special header fields for the notes system which are unregcognized by news. Other unrecognized fields are being generated by ARPA-gatewayed newsgroups. The dynamic memory allocated for this use is never released. On Vaxes and 32-bitters this just make the RSS get larger and larger. On PDP-11's, however, readnews and expire will run out of memory, failing in peculiar ways. I previously posted a fix to expire, but have discovered that problem appears in readnews too. So here are some revised fixes that supercede my previous one to alleviate the problem. The fixes are to header.c, expire.c, ifuncs.c, rfuncs.c, and rfuncs2.c. In the case of header.c and expire.c, I am including diffs from older pre-fix versions. --peter gross hao!pag *** old/header.c Thu Mar 29 10:44:00 1984 --- header.c Thu Mar 29 10:43:28 1984 *************** *** 9,14 * * 11/12/83 PAG Bug fix: missing site in path when prefix of current * site */ static char *SccsId = "@(#)header.c 3.4 3/29/84"; --- 9,21 ----- * * 11/12/83 PAG Bug fix: missing site in path when prefix of current * site + * + * 02/15/84 PAG Added check for failed malloc() + * + * 03/14/84 PAG Bug fix (typo) from USENET + * + * 03/26/84 PAG Bug fix: free() previously allocated memory in + * unrec[] array to prevent memory exhaustion */ static char *SccsId = "@(#)header.c 3.7 3/28/84"; *************** *** 11,17 * site */ ! static char *SccsId = "@(#)header.c 3.4 3/29/84"; #include #include --- 18,24 ----- * unrec[] array to prevent memory exhaustion */ ! static char *SccsId = "@(#)header.c 3.7 3/28/84"; #include #include *************** *** 37,42 int wholething; { register int len; if (wholething) bclear((char *) hp, sizeof (*hp)); --- 44,50 ----- int wholething; { register int len; + register short i; if (wholething) { *************** *** 39,44 register int len; if (wholething) bclear((char *) hp, sizeof (*hp)); seenrelay = 0; --- 47,66 ----- register short i; if (wholething) + { + /* + * Prevent memory exhaustion due to repeated malloc()'s + * of unrecognized header fields. Note that any local struct + * hbuf declarations used as args to hread() should zero out + * the unrec[] array, or mass confusion will result when this + * code is executed, and random stack values are given as + * arguments to free() + */ + for(i=0;iunrec[i] != (char *) NULL) + free(hp->unrec[i]); + else + break; bclear((char *) hp, sizeof (*hp)); } seenrelay = 0; *************** *** 40,46 if (wholething) bclear((char *) hp, sizeof (*hp)); ! seenrelay = 0; /* Check that it's a B news style header. */ --- 62,68 ----- else break; bclear((char *) hp, sizeof (*hp)); ! } seenrelay = 0; /* Check that it's a B news style header. */ *************** *** 130,138 int hdrlineno = 0; int iu; - for (iu=0; iuunrec[iu] = NULL; - i = type(bfr); do { curpos = ftell(fp); --- 152,157 ----- int hdrlineno = 0; int iu; i = type(bfr); do { curpos = ftell(fp); *************** *** 213,218 case OTHER: if (unreccnt < NUNREC) { hp->unrec[unreccnt] = malloc(strlen(bfr) + 1); strcpy(hp->unrec[unreccnt], bfr); unreccnt++; } --- 232,239 ----- case OTHER: if (unreccnt < NUNREC) { hp->unrec[unreccnt] = malloc(strlen(bfr) + 1); + if(hp->unrec[unreccnt] == (char *) NULL) + xerror("frmread out of memory\n"); strcpy(hp->unrec[unreccnt], bfr); unreccnt++; } *************** *** 574,580 while ((c = getc(fp)) == ' ' || c == '\t') { /* for each cont line */ /* Continuation line. */ ! while ((c = getc(fp)) == ' ' || c == 't') /* skip white space */ ; if (tp-cp < len) {*tp++ = ' '; *tp++ = c;} while ((c = getc(fp)) != '\n' && c != EOF) --- 595,601 ----- while ((c = getc(fp)) == ' ' || c == '\t') { /* for each cont line */ /* Continuation line. */ ! while ((c = getc(fp)) == ' ' || c == '\t') /* skip white space */ ; if (tp-cp < len) {*tp++ = ' '; *tp++ = c;} while ((c = getc(fp)) != '\n' && c != EOF) *************** *** old/expire.c Thu Mar 29 09:27:28 1984 --- expire.c Wed Mar 28 09:42:25 1984 *************** *** 24,29 * 10/08/83 PAG Bug fix from USENET -- mkparents() has no return val * * 10/27/83 PAG Additions from Mark to remove junk articles */ static char *SccsId = "@(#)expire.c 3.7 3/29/84"; --- 24,35 ----- * 10/08/83 PAG Bug fix from USENET -- mkparents() has no return val * * 10/27/83 PAG Additions from Mark to remove junk articles + * + * 01/15/84 PAG Bug fix: repeated hread()'s can cause memory + * exhaustion + * + * 03/26/84 PAG Change to memory bug fix -- unrec fields now cleared + * in frmread() */ static char *SccsId = "@(#)expire.c 3.9 3/28/84"; *************** *** 26,32 * 10/27/83 PAG Additions from Mark to remove junk articles */ ! static char *SccsId = "@(#)expire.c 3.7 3/29/84"; #include "params.h" #include "ndir.h" --- 32,38 ----- * in frmread() */ ! static char *SccsId = "@(#)expire.c 3.9 3/28/84"; #include "params.h" #include "ndir.h" *************** *** 211,216 ohfd = xfopen(ARTFILE, "r"); nhfd = xfopen(NARTFILE, "w"); } while (TRUE) { if (nohistory) { --- 217,224 ----- ohfd = xfopen(ARTFILE, "r"); nhfd = xfopen(NARTFILE, "w"); } + for(i=0;is_name, sp->s_xmit); #endif ifp = xfopen(file, "r"); if (hread(&hh, ifp, TRUE) == NULL) return; --- 353,360 ----- #ifdef DEBUG fprintf(stderr, "xmit %s to %s using %s\n", file, sp->s_name, sp->s_xmit); #endif + for(c=0;c