Skip to main content.
home | support | download

Back to List Archive

bug(?) in swish regex - FOLLOWUP

From: Rick Beebe <richard.beebe(at)not-real.yale.edu>
Date: Mon Apr 12 1999 - 18:08:07 GMT
Roy Tennant wrote:
> 
> This is now available in the Patches directory:
> 
> http://sunsite.berkeley.edu/SWISH-E/Patches/
> 
> Roy
> 
> >Date: Fri, 09 Apr 1999 11:26:19 -0400
> >From: Rick Beebe <richard.beebe@yale.edu>
> >Subject: bug(?) in swish regex
> >Organization: Yale University School of Medicine
> >
> >I've had regular unexplained crashes in Swish 1.3.1 running under Digital
> >Unix 4.0D. The crash is always a segmentation fault in matchARegex. After a
> >bunch of experimentation (I haven't done anything with regex before) I added
> >regfree calls to the routine and that fixed _most_ of the crashes. I'm not
> >sure why it should make a difference--I would have thought re would be freed
> >when leaving the routine--but it did. It still crashes occasionally--once
> >every three or four days--but it never used to even make it through a night
> >before.

Hmm. I was just looking through the patches directory (I hadn't realized it
was there). There's another patch--'memoryleak', submitted Jan 20 by Marc
Perrin--which details this exact same problem and solution on HPUX. I guess
it's a common enough problem that these patches ought to end up in 1.3.3,
eh?

I noticed, also, that the 'memoryleak' also adds some other regfree calls.
That made me look a little closer--I'd focused on the matchARegex call
because that's where mine was crashing. The routine directly above
matchARegex also uses regcomp as does file.c. All are shown in 'memoryleak'
but I don't agree with placement of a couple of them. So, I've come up with
a new patch listed below with my versions. This also incorporates the
previous patch I submitted so it should probably replace it.

Just an FYI. Swish hasn't crashed since I incorporated these patches. I
currently regenerate 25 index files each night. The largest indexes 25,000
documents and creates a 38 meg file.

--Rick Beebe

*** file.c.orig	Fri Dec 11 13:54:51 1998
--- file.c	Fri Apr  9 11:49:11 1999
***************
*** 452,462 ****
  			
			if (tmpReplace->next) 
  				tmpReplace = tmpReplace->next;
! 			else
  				return;
  		}
  		tmpReplace = tmpReplace->next;
  	}
  }
  
  /* This is similar to the previous one, just kept separated because */
--- 452,465 ----
  
  			if (tmpReplace->next)
  				tmpReplace = tmpReplace->next;
! 			else {
!		                regfree(&re);
  				return;
+		        }
 		}
  		tmpReplace = tmpReplace->next;
  	}
+    regfree(&re);
  }
  
  /* This	is similar to the previous one,	just kept separated because */
***************
*** 481,486 ****
--- 484,490 ----
  		}
  		tmpReplace = tmpReplace->next;
  	}
+    regfree(&re);
  }/* end	of checkListRegex */


*** string.c.orig	Fri Apr  9 11:08:00 1999
--- string.c	Mon Apr 12 12:25:18 1999
***************
*** 566,577 ****
  
  	status = regcomp(&re, pattern, REG_EXTENDED);
  	if ( status != 0) {
  		return oldStr;
  	}
  
  	status = regexec(&re,str,(size_t)MAXPAR,pmatch,0);
! 	if (status != 0)
  		return oldStr;
  
  	tmpstr = str;
  	while (!status)	{
--- 566,580 ----
  
  	status = regcomp(&re, pattern, REG_EXTENDED);
  	if ( status != 0) {
+       	regfree(&re);
  		return oldStr;
  	}
  
  	status = regexec(&re,str,(size_t)MAXPAR,pmatch,0);
+       regfree(&re);
! 	if (status != 0)
  		return oldStr;
  
  	tmpstr = str;
  	while (!status)	{
***************
*** 599,617 ****
  /*---------------------------------------------------------*/
  /* Match a regex and a string */
  
! 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);
! 	if (status != 0)
  		return 0;
! 	
  	return 1;
  }
  /*-----------------------------------------------------*/
--- 599,622 ---*
  /*---------------------------------------------------------*/
  /* Match a regex and a string */
  
! int matchARegex( char *str, char *pattern)
  {
  	int  status;
! 	regex_t	re;
! 
  	status = regcomp(&re, pattern, REG_EXTENDED);
! 	if ( status != 0) {
!       	regfree(&re);
  		return 0;
!   	}
! 
  	status = regexec(&re,str,(size_t)0,NULL,0);
! 	if (status != 0) {
!       	regfree(&re);
  		return 0;
!    	}
! 
!    	regfree(&re);
  	return 1;
  }
  /*-----------------------------------------------------*/
Received on Mon Apr 12 11:07:11 1999