Regex code in libbalsa_scanner_imap_dir



I believe there's a problem in the regex code in libbalsa_scanner_imap_dir
(libbalsa/folder-scanners.c):

    if(!FileMask.rx) {
       FileMask.rx = (regex_t *) safe_malloc (sizeof (regex_t));
       if( (i=REGCOMP(FileMask.rx,"!^\\.[^.]",0)) != 0) {
           g_warning("FileMask regexp compilation failed with code%i.",
                     i);
           safe_free((void**)&FileMask.rx);
           return;
       }
    }
...
    regfree(FileMask.rx);
    libbalsa_unlock_mutt();

}

FileMask is external, and presumably initialized to zeros, so the first
time through, a regex_t is allocated and FileMask.rx is pointed to it. If
the REGCOMP succeeds (as it always has, for me), we use it and then regfree
the result before exiting. The *next* time through, FileMask.rx is still
nonNULL, so we don't REGCOMP again, but we regfree it again on returning.

This all seems to work somehow without pcre, but with pcre it corrupts the
heap:

MALLOC_CHECK_=2 gdb src/balsa
...
Program received signal SIGABRT, Aborted.
[Switching to Thread 1024 (LWP 1702)]
0x4068b5c1 in __kill () from /lib/libc.so.6
(gdb) bt
#0  0x4068b5c1 in __kill () from /lib/libc.so.6
#1  0x4042a38e in raise (sig=6) at signals.c:65
#2  0x4068c9a8 in abort () at ../sysdeps/generic/abort.c:88
#3  0x406dba61 in free_check () at malloc.c:4555
#4  0x406d972d in __libc_free (mem=0x812c930) at malloc.c:3022
#5  0x40617c70 in regfree () from /usr/lib/libpcreposix.so.0
#6  0x080a1884 in libbalsa_scanner_imap_dir (rnode=0x81669a8, 
    server=0x8168f10, path=0x8169ad8 "INBOX.Courses", subscribed=1,
depth=7, 
    folder_handler=0x8080084 <add_imap_folder>, 
    mailbox_handler=0x807ff0c <add_imap_mailbox>) at folder-scanners.c:201

Since the regex is hard-coded, the intent is probably to compile it once
and for all, in which case it presumably shouldn't be regfree'd on return.
If, less likely, the intent is to free it and recompile each time, then
FileMask.rx should be safe_free'd after regfree'ing it.

Either way, something needs to be fixed to live with pcre. Comments?

Peter




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]