It's UWAweek 8

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.
Displaying selected article
Showing 1 of 1168 articles.
Currently 3 other people reading this forum.


 UWA week 42 (2nd semester, week 12) ↓
SVG not supported

Login to reply

👍?
helpful
12:31pm Thu 19th Oct, Christopher M.

"Ashkaan Singh" <23*5*5*3@s*u*e*t*u*a*e*u*a*> wrote:
> When using the regcomp() function my code works here and there. To elaborate I have a separate helper function that gets called to check if one of the patterns match it and that function gets called for every file that is found in a directory. > > The issue is that sometimes the program will break at first few files after using the matching function or it will break in the middle where the matching function was working for the other files but not when it gets to there. > > The reason why it breaks is because it says "malloc: heap corruption detected free list is damaged". I make sure to use the regfree() function to clear space that was allocated to it.
Hello Ashkaan, It's almost impossible to diagnose the problem from your description, alone. Each process has a single heap, and that heap is shared by all (many) functions used in your program. We're aware of malloc/realloc/.... that directly manage our own memory requirements, but other functions such as fopen/opendir/readir/regcomp/regexec/.... also use that single heap. Thus any error or invalid memory access that corrupts the heap will have have a, usually fatal, effect when you use other functions, and those errors often 'reveal' themselves long after they have been caused. So it may not be the regex functions themselves that are raising the error. Do you know if/which exact regex function is raising the error? Also, just a hunch, you say that you're calling regfree() - is that at the end of your program, or after every attempt to match? If the latter, are you calling regcomp(), regexec(), and regfree() for every attempt to match? If so, instead, your could just call regcomp() once (in the whole program) for each pattern, match with the saved compiled patterns, and never call regfree().

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  5:07AM Sep 06 2023
Privacy policy