Bug#217092: libc6-dev: leaks memory in regcomp (/usr/include/regex.h)
On Wed, Oct 22, 2003 at 07:07:06PM +0200, Alexander Kjall wrote: > Package: libc6-dev > Version: 2.3.2-8 > Severity: normal > > A memoryleak in regcomp, a example program is included below plus some > output from valgrind. > > It might be that i use it wrongly but I don't think so. You're not calling regfree() between the first and second calls to regcomp(). Here's a patch: --- regcompleak.cpp.orig2003-10-22 19:01:32.0 +0100 +++ regcompleak.cpp 2003-10-22 19:03:46.0 +0100 @@ -14,6 +14,10 @@ { reg = new regex_t; } + else + { +regfree(reg); + } if(int err = regcomp(reg, "^[0-9]+:[A-Za-z,]+:.*$", 0)) cleanup(err); Cheers, -- Colin Watson [EMAIL PROTECTED]
Bug#217092: libc6-dev: leaks memory in regcomp (/usr/include/regex.h)
Package: libc6-dev Version: 2.3.2-8 Severity: normal A memoryleak in regcomp, a example program is included below plus some output from valgrind. It might be that i use it wrongly but I don't think so. #include #include #include #include void cleanup(int toexit); regex_t *reg; bool check_input(std::string in) { if(reg == 0) { reg = new regex_t; } if(int err = regcomp(reg, "^[0-9]+:[A-Za-z,]+:.*$", 0)) cleanup(err); regmatch_t ptype; return regexec(reg, in.c_str(), 0, &ptype, 0) != 0; } void cleanup(int toexit) { if(reg != 0) { regfree(reg); } exit(toexit); } int main(int argc, char *argv[]) { std::string in = "3520872:all:message"; check_input(in.c_str()); check_input(in.c_str()); cleanup(0); } and some of the output from valgrind ==28354== LEAK SUMMARY: ==28354==definitely lost: 348 bytes in 2 blocks. ==28354==possibly lost: 1280 bytes in 1 blocks. ==28354==still reachable: 5588 bytes in 90 blocks. ==28354== suppressed: 0 bytes in 0 blocks. ==28354== Reachable blocks (those to which a pointer was found) are not shown. ==28354== To see them, rerun with: --show-reachable=yes ==28354== -- System Information: Debian Release: testing/unstable Architecture: i386 Kernel: Linux paranor 2.4.21-4-k7 #1 Sun Aug 3 02:34:06 EST 2003 i686 Locale: LANG=sv_SE, LC_CTYPE=sv_SE Versions of packages libc6-dev depends on: ii libc6 2.3.2-8GNU C Library: Shared libraries an -- no debconf information
Bug#217092: libc6-dev: leaks memory in regcomp (/usr/include/regex.h)
On Wed, Oct 22, 2003 at 07:07:06PM +0200, Alexander Kjall wrote: > Package: libc6-dev > Version: 2.3.2-8 > Severity: normal > > A memoryleak in regcomp, a example program is included below plus some > output from valgrind. > > It might be that i use it wrongly but I don't think so. You're not calling regfree() between the first and second calls to regcomp(). Here's a patch: --- regcompleak.cpp.orig2003-10-22 19:01:32.0 +0100 +++ regcompleak.cpp 2003-10-22 19:03:46.0 +0100 @@ -14,6 +14,10 @@ { reg = new regex_t; } + else + { +regfree(reg); + } if(int err = regcomp(reg, "^[0-9]+:[A-Za-z,]+:.*$", 0)) cleanup(err); Cheers, -- Colin Watson [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Bug#217092: libc6-dev: leaks memory in regcomp (/usr/include/regex.h)
Package: libc6-dev Version: 2.3.2-8 Severity: normal A memoryleak in regcomp, a example program is included below plus some output from valgrind. It might be that i use it wrongly but I don't think so. #include #include #include #include void cleanup(int toexit); regex_t *reg; bool check_input(std::string in) { if(reg == 0) { reg = new regex_t; } if(int err = regcomp(reg, "^[0-9]+:[A-Za-z,]+:.*$", 0)) cleanup(err); regmatch_t ptype; return regexec(reg, in.c_str(), 0, &ptype, 0) != 0; } void cleanup(int toexit) { if(reg != 0) { regfree(reg); } exit(toexit); } int main(int argc, char *argv[]) { std::string in = "3520872:all:message"; check_input(in.c_str()); check_input(in.c_str()); cleanup(0); } and some of the output from valgrind ==28354== LEAK SUMMARY: ==28354==definitely lost: 348 bytes in 2 blocks. ==28354==possibly lost: 1280 bytes in 1 blocks. ==28354==still reachable: 5588 bytes in 90 blocks. ==28354== suppressed: 0 bytes in 0 blocks. ==28354== Reachable blocks (those to which a pointer was found) are not shown. ==28354== To see them, rerun with: --show-reachable=yes ==28354== -- System Information: Debian Release: testing/unstable Architecture: i386 Kernel: Linux paranor 2.4.21-4-k7 #1 Sun Aug 3 02:34:06 EST 2003 i686 Locale: LANG=sv_SE, LC_CTYPE=sv_SE Versions of packages libc6-dev depends on: ii libc6 2.3.2-8GNU C Library: Shared libraries an -- no debconf information -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]