[pcre-dev] Freeing memory in PCRE

Top Page
Delete this message
Author: Mark Burgess
Date:  
To: pcre-dev
Subject: [pcre-dev] Freeing memory in PCRE

Dear PCRE developers,

first of all thank you for your great work on this superior regex
library. I wonder if I could impose to ask a question -- replying to
me directly.

I am having trouble with memory leakage because I cannot understand
when I am supposed to free memory. On older version of the lib, my
code worked as I expected (Version: 7.2-14.6)

Now in the newer versions (Version: 7.8-1.38) I get double-free
segfaults from the same code. Is this a bug, or am I doing something
wrong? How should I be doing this?

I appreciate your help - see the commented free below, which I believe
should be there.

// compile regex -> rx

if ((rc =
pcre_exec(rx,NULL,teststring,strlen(teststring),0,0,ovector,OVECCOUNT))
>= 0)

{
*start = ovector[0];
*end = ovector[1];

   for (i = 0; i < rc; i++) /* make backref vars $(1),$(2) etc */
      {
      char substring[1024];
      char lval[4];
      char *backref_start = teststring + ovector[i*2];
      int backref_len = ovector[i*2+1] - ovector[i*2];


      memset(substring,0,1024);
      strncpy(substring,backref_start,backref_len);
      snprintf(lval,3,"%d",i);
      ForceScalar(lval,substring);
      }


pcre_free(rx);
return true;
}
else
{
*start = 0;
*end = 0;
//pcre_free(rx); this segfaults, why?
return false;
}


Thank you

--
Mark Burgess

-------------------------------------------------
Professor of Network and System Administration
Oslo University College, Norway

Personal Web: http://www.iu.hio.no/~mark
Office Telf : +47 22453272
-------------------------------------------------