Date:

Wed Jun 14 17:32:42 PDT 1995

Description

Postgres95 leaks memory whenever regexp operations (e.g. the ~ operator) is used. We mistakenly assumed that only only NetBSD systems used regex.h instead of regexp.h. As a result, most Linux systems exhibit this problem.

Fix

Apply this patch.

===================================================================
*** 1.5	1995/05/14 23:05:48
--- src/backend/utils/adt/regexp.c	1995/06/15 00:07:23
***************
*** 48,60 ****
  #if defined(DISABLE_XOPEN_NLS)
  #undef _XOPEN_SOURCE
  #endif /* DISABLE_XOPEN_NLS */
  #ifndef WIN32
! # if defined(PORTNAME_netbsd)
! # include 
! # include 
! # else
! # include 
! # endif /* netbsd */
  #endif /* WIN32 why is this necessary? */
  
  /*
--- 48,65 ----
  #if defined(DISABLE_XOPEN_NLS)
  #undef _XOPEN_SOURCE
  #endif /* DISABLE_XOPEN_NLS */
+ 
  #ifndef WIN32
! 
! /* distinguish using regex.h and regexp.h */
! #if defined(PORTNAME_netbsd) || defined(PORTNAME_linux)
! #define USE_REGEX
! #include 
! #include 
! #else
! #include 
! #endif 
! 
  #endif /* WIN32 why is this necessary? */
  
  /*
***************
*** 74,80 ****
      if (!s || !p)
  	return FALSE;
      
! #if !defined(PORTNAME_netbsd)
      expbuf = (char *) palloc(EXPBUFSZ);
      endbuf = expbuf + (EXPBUFSZ - 1);
  #endif
--- 79,85 ----
      if (!s || !p)
  	return FALSE;
      
! #if !defined(USE_REGEX)
      expbuf = (char *) palloc(EXPBUFSZ);
      endbuf = expbuf + (EXPBUFSZ - 1);
  #endif
***************
*** 92,98 ****
      memmove(pterm, p->vl_dat, p->vl_len - sizeof(int32));
      *(pterm + p->vl_len - sizeof(int32)) = (char)NULL;
      
! #if defined(PORTNAME_netbsd)
      {
  	regex_t 	re;
  
--- 97,103 ----
      memmove(pterm, p->vl_dat, p->vl_len - sizeof(int32));
      *(pterm + p->vl_len - sizeof(int32)) = (char)NULL;
      
! #if defined(USE_REGEX)
      {
  	regex_t 	re;
  
***************
*** 108,114 ****
      result = step(sterm, expbuf);
      
      pfree(expbuf);
! #endif /* !__NetBSD__ */
  
      pfree(sterm);
      pfree(pterm);
--- 113,119 ----
      result = step(sterm, expbuf);
      
      pfree(expbuf);
! #endif /* USE_REGEX */
  
      pfree(sterm);
      pfree(pterm);
***************
*** 131,137 ****
      if (!s || !p)
  	return FALSE;
      
! #if !defined(PORTNAME_netbsd)
      expbuf = (char *) palloc(EXPBUFSZ);
      endbuf = expbuf + (EXPBUFSZ - 1);
  #endif
--- 136,142 ----
      if (!s || !p)
  	return FALSE;
      
! #if !defined(USE_REGEX)
      expbuf = (char *) palloc(EXPBUFSZ);
      endbuf = expbuf + (EXPBUFSZ - 1);
  #endif
***************
*** 149,155 ****
      memmove(pterm, p->vl_dat, p->vl_len - sizeof(int32));
      *(pterm + p->vl_len - sizeof(int32)) = (char)NULL;
      
! #if defined(PORTNAME_netbsd)
      {
  	regex_t 	re;
  
--- 154,160 ----
      memmove(pterm, p->vl_dat, p->vl_len - sizeof(int32));
      *(pterm + p->vl_len - sizeof(int32)) = (char)NULL;
      
! #if defined(USE_REGEX)
      {
  	regex_t 	re;
  
***************
*** 186,192 ****
      if (!s || !p)
  	return FALSE;
      
! #if !defined(PORTNAME_netbsd)
      expbuf = (char *) palloc(EXPBUFSZ);
      endbuf = expbuf + (EXPBUFSZ - 1);
  #endif
--- 191,197 ----
      if (!s || !p)
  	return FALSE;
      
! #if !defined(USE_REGEX)
      expbuf = (char *) palloc(EXPBUFSZ);
      endbuf = expbuf + (EXPBUFSZ - 1);
  #endif
***************
*** 204,210 ****
      memmove(pterm, p->vl_dat, p->vl_len - sizeof(int32));
      *(pterm + p->vl_len - sizeof(int32)) = (char)NULL;
      
! #if defined(PORTNAME_netbsd)
      {
  	regex_t 	re;
  
--- 209,215 ----
      memmove(pterm, p->vl_dat, p->vl_len - sizeof(int32));
      *(pterm + p->vl_len - sizeof(int32)) = (char)NULL;
      
! #if defined(USE_REGEX)
      {
  	regex_t 	re;
  
***************
*** 241,247 ****
      if (!s || !p)
  	return FALSE;
      
! #if !defined(PORTNAME_netbsd)
      expbuf = (char *) palloc(EXPBUFSZ);
      endbuf = expbuf + (EXPBUFSZ - 1);
  #endif
--- 246,252 ----
      if (!s || !p)
  	return FALSE;
      
! #if !defined(USE_REGEX)
      expbuf = (char *) palloc(EXPBUFSZ);
      endbuf = expbuf + (EXPBUFSZ - 1);
  #endif
***************
*** 259,265 ****
      memmove(pterm, p->vl_dat, p->vl_len - sizeof(int32));
      *(pterm + p->vl_len - sizeof(int32)) = (char)NULL;
      
! #if defined(PORTNAME_netbsd)
      {
  	regex_t 	re;
  
--- 264,270 ----
      memmove(pterm, p->vl_dat, p->vl_len - sizeof(int32));
      *(pterm + p->vl_len - sizeof(int32)) = (char)NULL;
      
! #if defined(USE_REGEX)
      {
  	regex_t 	re;
  
***************
*** 274,280 ****
      /* do the regexp matching */
      result = step(sterm, expbuf);
      pfree(expbuf);
! #endif
      
      pfree(sterm);
      pfree(pterm);
--- 279,285 ----
      /* do the regexp matching */
      result = step(sterm, expbuf);
      pfree(expbuf);
! #endif /*USE_REGEX */
      
      pfree(sterm);
      pfree(pterm);
***************
*** 307,313 ****
      sbuf = (char *) palloc(s->vl_len - sizeof(int32) + 1);
      pbuf = (char *) palloc(p->vl_len - sizeof(int32) + 1);
      
! #if !defined(PORTNAME_netbsd)
      expbuf = (char *) palloc(EXPBUFSZ);
      endbuf = expbuf + (EXPBUFSZ - 1);
  #endif
--- 312,318 ----
      sbuf = (char *) palloc(s->vl_len - sizeof(int32) + 1);
      pbuf = (char *) palloc(p->vl_len - sizeof(int32) + 1);
      
! #if !defined(USE_REGEX)
      expbuf = (char *) palloc(EXPBUFSZ);
      endbuf = expbuf + (EXPBUFSZ - 1);
  #endif
***************
*** 318,324 ****
      *(pbuf + p->vl_len - sizeof(int32)) = (char)NULL;
      
      
! #if defined(PORTNAME_netbsd)
      {
  	regex_t 	re;
  
--- 323,329 ----
      *(pbuf + p->vl_len - sizeof(int32)) = (char)NULL;
      
      
! #if defined(USE_REGEX)
      {
  	regex_t 	re;
  
***************
*** 333,339 ****
      /* do the regexp matching */
      result = step(sbuf, expbuf);
      pfree(expbuf);
! #endif
      
      pfree(sbuf);
      pfree(pbuf);
--- 338,344 ----
      /* do the regexp matching */
      result = step(sbuf, expbuf);
      pfree(expbuf);
! #endif /* USE_REGEX */
      
      pfree(sbuf);
      pfree(pbuf);