This patch is now available in the SWISH-E Patches directory:
http://sunsite.berkeley.edu/SWISH-E/Patches/
Roy Tennant
---------- Forwarded message ----------
Date: Mon, 18 Jan 1999 17:18:01 +0100
From: MARC_PERRIN@HP-France-om4.om.hp.com
To: ghill@library.berkeley.edu, rtennant@library.berkeley.edu
Cc: BAUSCH_BERND/HP-France_om5@rossini.grenoble.hp.com,
DECROIX_DARYL/HP-Boise_om2@rossini.grenoble.hp.com, dskinner@boi.hp.com,
mariaux@trotek.ec-lyon.fr,
VONALTEN_TOM/HP-Boise_unixgw1@rossini.grenoble.hp.com
Subject: Fix Memory Leak in Swish-e 1.2.4
Hello,
Thanks to a german collegue (Bernd Bausch) who used a "memory leak
detection tool" written by a japanese engineer from HP, we have identified
some of the main memory leaks of SWISH-E 1.2.4 which prevented me to run
it on a HP-UX 10.20 machine.
That's the bug I reported to you last November.
The leak was due to the fact that swish-e uses the functions regcomp() and
regexec(), but fails to call regfree() to release internally allocated memory.
We suppose that on other UNIXes, regfree() is not needed.
Now, indexing 1500 files (44000 unique words) takes 9.6 Mbytes of memory,
almost the same as with swish-e 1.1 (10 Mbytes).
before, it crashed in the middle when reaching 64 Mbytes.
The 2 files to fix are string.c and file.c
Here is how I tried to fix the files, not being a C specialist though ...
----------------------------------------------------------------------------
string.c:
---------
/* Save the old string just in case */
strcpy(oldStr,str);
status = regcomp(&re, pattern, REG_EXTENDED);
if ( status != 0) {
return oldStr;
}
status = regexec(&re,str,(size_t)MAXPAR,pmatch,0);
regfree(&re); /** Marc Perrin ## 18Jan99 **/
if (status != 0)
return oldStr;
---------------------------------------------------------------
int matchARegex( char *str, char *pattern)
{
int status;
regex_t re;
status = regcomp(&re, pattern, REG_EXTENDED);
if ( status != 0)
return 0;
status = regexec(&re,str,(size_t)0,NULL,0);
regfree(&re); /** Marc Perrin ## 18Jan99 **/
if (status != 0)
return 0;
return 1;
}
----------------------------------------------------------------------------
file.c:
-------
status = regcomp(&re,patt, REG_EXTENDED);
if (status != 0) {
printf ("Illegal regular expression %s\n", patt);
exit(0);
}
regfree(&re); /** Marc Perrin ## 18Jan99 **/
---------------------------------------------------------------
while (tmpReplace) {
strcpy(patt,tmpReplace->line);
if (patt == NULL)
return;
status = regcomp(&re,patt, REG_EXTENDED);
if (status != 0) {
printf ("Illegal regular expression %s\n", patt);
exit(0);
}
regfree(&re); /** Marc Perrin ## 18Jan99 **/
tmpReplace = tmpReplace->next;
----------------------------------------------------------------------------
Please note that before that, I also had to rewrite some pieces in
order to compile successfully:
check.c:
--------
int isvowel(char c)
{
instead of
int isvowel(c)
char c;
{
index.c:
--------
int isIgnoreLastChar(char c)
{
instead of
int isIgnoreLastChar(c)
char c;
{
string.c:
---------
int iswordchar(char c)
{
instead of
int iswordchar(c)
char c;
{
---------------------------------------------------------------
Best Regards
Marc PERRIN
TPEC Webmaster
Education Engineering
TPEC - Customer Support Europe
._______________________________________.____________________________________.
| HEWLETT PACKARD - TPEC | Marc PERRIN |
| /_ __ Tech. Planning & Education Ctr| |
|/ / /_/ Bd Steve Biko | E-Mail: marc_perrin@hp.com |
| / 38090 VILLEFONTAINE | tel: +33 (0)4 74 99 31 52 voicemail|
| FRANCE | fax: +33 (0)4 74 99 30 05 |
._______________________________________.____________________________________.
Received on Wed Jan 20 11:24:01 1999