From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10419 invoked by alias); 19 Sep 2005 21:24:55 -0000 Mailing-List: contact glibc-bugs-regex-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-regex-owner@sources.redhat.com Received: (qmail 9986 invoked by uid 48); 19 Sep 2005 21:24:46 -0000 Date: Mon, 19 Sep 2005 21:24:00 -0000 From: "root at liwave dot com" To: glibc-bugs-regex@sources.redhat.com Message-ID: <20050919212445.1357.root@liwave.com> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug regex/1357] New: memory leak in re_compile_pattern() X-Bugzilla-Reason: CC X-SW-Source: 2005-09/txt/msg00065.txt.bz2 List-Id: Calling re_compile_pattern results in a memory leak proportional to the size of the Pattern String. See Example code below: #include #include int main() { struct re_pattern_buffer *patBuf; const char *ErrStr; char PatStr[128]; unsigned int i; patBuf = (struct re_pattern_buffer *) malloc(sizeof(struct re_pattern_buffer)); if (!patBuf) exit(0); memset(patBuf, 0, sizeof(struct re_pattern_buffer)); patBuf->translate = 0; patBuf->fastmap = 0; patBuf->buffer = (char *) malloc(2048); //Optional patBuf->allocated = 2048; patBuf->regs_allocated = REGS_UNALLOCATED; /Optional patBuf->used = 0; re_set_syntax (RE_SYNTAX_POSIX_EGREP); //Optional for (i = 0; i < 10000; i++) { sprintf(PatStr, "TEST.?STRING%d", i); //This can be anything memset(patBuf->buffer, 0, 2048); ErrStr = re_compile_pattern(PatStr, strlen(PatStr), patBuf); if (ErrStr) printf("ErrStr = %s\n",ErrStr); } //endof for (i = 0; i < 10000; i++) if (patBuf->buffer) free(patBuf->buffer); if (patBuf) free(patBuf); exit(1); } //endof main() Leak was introduced after glibc-2.2.2. This code works fine on a linux 2.4 system running with glibc-2.2.2, leak occures in glibc 2.3.5 and 2.3.1 glibc 2.3.5 was compiled with: CFLAGS="-O3 -march=i686 -mcpu=i686 -funroll-loops -fomit-frame-pointer - fexpensive-optimizations -pipe" -- Summary: memory leak in re_compile_pattern() Product: glibc Version: 2.3.5 Status: NEW Severity: normal Priority: P2 Component: regex AssignedTo: gotom at debian dot or dot jp ReportedBy: root at liwave dot com CC: glibc-bugs-regex at sources dot redhat dot com,glibc- bugs at sources dot redhat dot com GCC host triplet: Linux gentoo 2.6.7-hardened-r18 #2 SMP Sun Jan 16 18:37:38 EST 2 http://sourceware.org/bugzilla/show_bug.cgi?id=1357 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.