Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak when calling current_zone() #650

Closed
satishbhat-umd opened this issue Feb 25, 2021 · 10 comments
Closed

Memory Leak when calling current_zone() #650

satishbhat-umd opened this issue Feb 25, 2021 · 10 comments

Comments

@satishbhat-umd
Copy link
Contributor

=================================================================
==32643==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 72 byte(s) in 1 object(s) allocated from:
#0 0x568e50 in calloc (/build/sbhat/Laser/BT.BelvedereExchange/Tests/BT.BelvedereExchange.Tests+0x568e50)
#1 0x7fffe1767163 (/lib64/libnsspem.so+0x15163)

Direct leak of 72 byte(s) in 1 object(s) allocated from:
#0 0x568e50 in calloc (/build/sbhat/Laser/BT.BelvedereExchange/Tests/BT.BelvedereExchange.Tests+0x568e50)
#1 0x7fffe8ef4773 (/lib64/libnss3.so+0x75773)

Getting the following output when compiling using -fsanitize=address when the date::current_zone() fn is called

@HowardHinnant
Copy link
Owner

What OS/platform?

@satishbhat-umd
Copy link
Contributor Author

CentOS 7.3

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

@HowardHinnant
Copy link
Owner

Is it reproduceable in a small test such as:

#include "date/tz.h"

int
main()
{
    auto tz = date::current_zone();
}

And what build settings are you using (e.g. USE_OS_TZDB)?

@HowardHinnant
Copy link
Owner

Does it reproduce with this program?

#include "date/tz.h"

int
main()
{
    auto tz = date::locate_zone("Europe/Berlin");
}

@satishbhat-umd
Copy link
Contributor Author

Reproduces in both cases and USE_OS_TZDB was not set when compiling the library (i.e. it will use a curl request to fetch the tzdb)

@HowardHinnant
Copy link
Owner

I'm not currently able to reproduce this on my platform. Can you use this tool to locate the source line in tz.cpp where the leaked memory is allocated?

@satishbhat-umd
Copy link
Contributor Author

It appears to be allocated in the curl_init function. I see the curl_deleter struct is passed to the destructor of the CURL object, but it seems to only call curl_easy_cleanup(...) in operator(). If I add a call to ::curl_global_cleanup() after that and recompile the library, I am able to call current_zone() without any memory leaks.

@HowardHinnant
Copy link
Owner

Really nice detective work. I would not have found this.

Would you like for me to just fix it, or would you like to submit a P/R?

@satishbhat-umd
Copy link
Contributor Author

Created a P/R here - #652

@HowardHinnant
Copy link
Owner

Fixed by #652

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants