unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Austin Ray <austin@austinray.io>
To: notmuch@notmuchmail.org
Subject: Memory leak in notmuch_database_destroy()
Date: Wed, 5 Jan 2022 17:45:38 -0500	[thread overview]
Message-ID: <20220105224538.m36lnjn7rf3ieonc@athena> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 2423 bytes --]

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

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



             reply	other threads:[~2022-01-05 22:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-05 22:45 Austin Ray [this message]
2022-01-08 18:28 ` [PATCH 1/2] lib/config: move g_key_File_get_string before continue David Bremner
2022-01-08 18:28   ` [PATCH 2/2] lib/database: delete stemmer on destroy David Bremner
2022-01-24 14:58 ` Memory leak in notmuch_database_destroy() David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220105224538.m36lnjn7rf3ieonc@athena \
    --to=austin@austinray.io \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).