Subject: regcomp(3) memory leak
To: None <>
From: Takayoshi Kochi <>
List: netbsd-users
Date: 12/09/2001 21:24:32

I'm hit by a memory leak problem in regcomp(3) on 1.5 and very
recent 1.5-current.

This case is easily repeatable by attached program.
If you give it a regular expression (e.g. '^[a-z]+'), the program
searches the pattern against the same string forever.
In special case, when I give it '\(.\)\1\1\1' (any 4 sequential
characters), its size will be increasing to its limit (which
can be monitord by top(1)).
But strangely, when I give '\(.\)\1\1' (any 3 sequential characters)
the problem won't occur.

I saw the same problem on FreeBSD 4.4.

Am I missing something?  Or if this is a real problem,
I'll send-pr to both NetBSD and FreeBSD.


#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <regex.h>

main(int argc, char *argv[])
        int c, ret, cflags;
        regex_t re;
        char buf[BUFSIZ];

        cflags = REG_ICASE;

        while(1) {
                ret = regcomp(&re, argv[1], cflags);
                if (ret) {
                        regerror(ret, &re, buf, BUFSIZ);
                        fprintf(stderr, "%s\n", buf);
                ret = regexec(&re, "bbbddeeefffefjaidf", 0, 0, 0);

Takayoshi Kochi <>