[ace-users] regcomp, regexec, regfree Problems on Linux

jhoffert at dre.vanderbilt.edu jhoffert at dre.vanderbilt.edu
Thu Sep 27 06:38:38 CDT 2007

Hi, all.

I modified the program that I sent out yesterday slightly so that the
problems go away. However, I don't understand why my changes make a

I made the regex_t data member public, removed the call to regfree in the
destructor, and called ::regfree(&matcher.regexp_) in main () right before
the return statement.

Does anyone have any idea what the problem is?



> Hi, Doug.
>> Hi Joe,
>>    Could you post a small, self-contained example that illustrates the
>> problem so that people could try this on other versions of UNIX/Linux?
> Sure. I've attached the file.
> I first tried a non-encapsulated test program with no objects but I didn't
> have problems there. The problem seems to occur when I call regcomp () in
> the constructor, regexec () in the operator ()() function overload method,
> and regfree () in the destructor as illustrated in the attached file.
> valgrind reports memory problems and I get a segmentation fault. If I
> comment out the call to regfree then there's no segmentation fault.
> Thanks for the help.
> -Joe
>> thanks,
>>         Doug
>>>I'm using regcomp, regexec, and regfree on Linux (i.e., Linux
>>> #1 SMP Thu Aug 30 13:47:21 EDT 2007 i686 i686 i386
>>>GNU/Linux) and I've run into memory leak problems. Doug Schmidt thought
>>>that these problems had been seen before and suggested I post to this
>>>I originally just called regcomp once, regexec as many times as needed,
>>>and then regfree once. However, valgrind tells me there are memory
>>>problems. The only way I saw to fix the memory problems was to call
>>>regcomp, regexec, and regfree consecutively (which defeats the purpose
>>>of having regcomp).
>>>Does anyone have any information on the problem I'm seeing?
>>>Thanks for your help.
>> --
>> Dr. Douglas C. Schmidt                       Professor and Associate
>> Chair
>> Electrical Engineering and Computer Science  TEL: (615) 343-8197
>> Vanderbilt University                        WEB:
>> www.dre.vanderbilt.edu/~schmidt
>> Nashville, TN 37203                          NET:
>> d.schmidt at vanderbilt.edu

More information about the Ace-users mailing list