Skip to content

Conversation

@kallewoof
Copy link
Contributor

This PR intends to plug some leaks. It specifically implements adherence to the requirement in BDB to close a handle which failed to open (https://docs.oracle.com/cd/E17276_01/html/api_reference/C/dbopen.html):

The DB->open() method returns a non-zero error value on failure and 0 on success. If DB->open() fails, the DB->close() method must be called to discard the DB handle.

@practicalswift
Copy link
Contributor

Concept ACK! Nice find 👍

@fanquake fanquake added the Wallet label Aug 9, 2017
Copy link
Contributor

@gmaxwell gmaxwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@maflcko
Copy link
Member

maflcko commented Aug 10, 2017

utACK 03bc719

@paveljanik
Copy link
Contributor

utACK 03bc719

} else {
pdbCopy->close(0);
}
delete pdbCopy;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it always close pdbCopy before deleting it, not just on failure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line #537 closes for fSuccess being false and #542 for true. Am I missing a case?

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 03bc719.

BTW, how did you catch this?

@kallewoof
Copy link
Contributor Author

@promag I ran bitcoind through Instruments on a mac, and noticed I think 40k leaks (not 40 kb, 40 thousand occurrences..) on startup. One of the traces for leaked memory was the DB open call.

@jonasschnelli
Copy link
Contributor

utACK 03bc719

@jonasschnelli jonasschnelli merged commit 03bc719 into bitcoin:master Aug 15, 2017
jonasschnelli added a commit that referenced this pull request Aug 15, 2017
03bc719 [wallet] Close DB on error. (Karl-Johan Alm)

Pull request description:

  This PR intends to plug some leaks. It specifically implements adherence to the requirement in BDB to close a handle which failed to open (https://docs.oracle.com/cd/E17276_01/html/api_reference/C/dbopen.html):

  > The `DB->open()` method returns a non-zero error value on failure and 0 on success. If `DB->open()` fails, the `DB->close()` method must be called to discard the DB handle.

Tree-SHA512: cc1f2b925ef3fd6de785f62108fbc79454443397f80707762acbc56757841d2c32b69c0234f87805571aa40c486da31f315ca4c607a2c7d1c97c82a01301e2a6
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
schancel pushed a commit to schancel/bitcoin-abc that referenced this pull request Apr 19, 2019
Summary:
[wallet] Close DB on error.

Backport of Core PR 11017
bitcoin/bitcoin#11017

Completes T606

Test Plan:
make check
test_runner.py
Sanity check open and close (both by exiting and by ctrl-C interrupt) bitcoin-qt

Reviewers: jasonbcox, deadalnix, Fabien, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D2807
proteanx pushed a commit to devaultcrypto/devault that referenced this pull request Apr 26, 2019
Summary:
[wallet] Close DB on error.

Backport of Core PR 11017
bitcoin/bitcoin#11017

Completes T606

Test Plan:
make check
test_runner.py
Sanity check open and close (both by exiting and by ctrl-C interrupt) bitcoin-qt

Reviewers: jasonbcox, deadalnix, Fabien, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D2807
Greg-Griffith added a commit to Greg-Griffith/eccoin that referenced this pull request May 1, 2019
codablock pushed a commit to codablock/dash that referenced this pull request Sep 25, 2019
03bc719 [wallet] Close DB on error. (Karl-Johan Alm)

Pull request description:

  This PR intends to plug some leaks. It specifically implements adherence to the requirement in BDB to close a handle which failed to open (https://docs.oracle.com/cd/E17276_01/html/api_reference/C/dbopen.html):

  > The `DB->open()` method returns a non-zero error value on failure and 0 on success. If `DB->open()` fails, the `DB->close()` method must be called to discard the DB handle.

Tree-SHA512: cc1f2b925ef3fd6de785f62108fbc79454443397f80707762acbc56757841d2c32b69c0234f87805571aa40c486da31f315ca4c607a2c7d1c97c82a01301e2a6
@kallewoof kallewoof deleted the close-dbenv branch October 17, 2019 08:41
furszy added a commit to PIVX-Project/PIVX that referenced this pull request Feb 12, 2021
0c4b20f [Wallet] Close DB on error (Fuzzbawls)

Pull request description:

  Coming from bitcoin#11017

  > This PR intends to plug some leaks. It specifically implements adherence to the requirement in BDB to close a handle which failed to open (https://docs.oracle.com/cd/E17276_01/html/api_reference/C/dbopen.html):
  >
  > >   The DB->open() method returns a non-zero error value on failure and 0 on success. If DB->open() fails, the DB->close() method
  > >   must be called to discard the DB handle.

ACKs for top commit:
  random-zebra:
    utACK 0c4b20f
  furszy:
    utACK 0c4b20f

Tree-SHA512: 826e1eb651b93b62e7e01701b7d233902ddcf6a995d09e020194523ef3834162b397e186477e31f3e0b1a11bc80483635f7bc731907e9367ff7f38a3ddc782ae
barton2526 added a commit to barton2526/Gridcoin-Research that referenced this pull request Jul 12, 2021
barton2526 added a commit to barton2526/Gridcoin-Research that referenced this pull request Jul 12, 2021
barton2526 added a commit to barton2526/Gridcoin-Research that referenced this pull request Jul 12, 2021
Ref: bitcoin/bitcoin#11017

I thought better and moved the trivial to another PR.  This will be exclusively the DB change because it is a regression risk.
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants