Memory leak in notmuch_database_destroy()

Subject:Memory leak in notmuch_database_destroy()

Date:Wed, 5 Jan 2022 17:45:38 -0500

To:notmuch@notmuchmail.org

Cc:

From:Austin Ray


Hi,

libnotmuch 5.5.0 (notmuch 0.34.2) leaks memory when opening a database
with 'notmuch_database_open_with_config()' and cleaning it up with
'notmuch_database_destroy()'. I've included a reproducer program (based
on an existing notmuch test) and ASAN output below.

Replacing 'notmuch_database_destroy()' with 'notmuch_database_close()'
or omitting the database clean-up entirely resolves all but the first
ASAN entry. There's no leak if 'notmuch_database_open_with_config()'
returns an error.

Thanks!

Austin

Reproducer program:

#include <notmuch.h>
#include <stdio.h>

int main(int argc, char **argv) {
  notmuch_database_t *db = NULL;

  notmuch_status_t st = notmuch_database_open_with_config(
      argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, argv[2], NULL, &db, NULL);

  if (db != NULL) {
    notmuch_database_destroy(db);
  }

  printf("db != NULL: %d\n", db != NULL);
}

ASAN output:

=================================================================
==1059281==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7fb9d1230777 in __interceptor_malloc (/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/libasan.so.6+0xb6777)
    #1 0x7fb9d0a2b098 in g_malloc (/usr/lib64/libglib-2.0.so.0+0x5b098)

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7fb9d1232137 in operator new(unsigned long) (/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/libasan.so.6+0xb8137)
    #1 0x7fb9d1164ef4  (/usr/lib64/libnotmuch.so.5+0x2aef4)
    #2 0x7fb9d1165abc in notmuch_database_open_with_config (/usr/lib64/libnotmuch.so.5+0x2babc)

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7fb9d1232137 in operator new(unsigned long) (/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/libasan.so.6+0xb8137)
    #1 0x7fb9d08ef849  (/usr/lib64/libxapian.so.30+0x15d849)
    #2 0x7fb9d1165abc in notmuch_database_open_with_config (/usr/lib64/libnotmuch.so.5+0x2babc)

Indirect leak of 25 byte(s) in 1 object(s) allocated from:
    #0 0x7fb9d1230777 in __interceptor_malloc (/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/libasan.so.6+0xb6777)
    #1 0x7fb9d08efded  (/usr/lib64/libxapian.so.30+0x15dded)

SUMMARY: AddressSanitizer: 121 byte(s) leaked in 4 allocation(s).

-- 
https://austinray.io
Open Source Maintainer, Software Engineer, Keyboard Enthusiast
GPG: 0127 ED83 B939 CCC9 8082 476E 1AA0 B115 C8AC 2C9E
signature.asc (application/pgp-signature)
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: