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

ASAN detects memory leak in PARSE_SCFG_STRING #1

Open
MasterAler opened this issue Apr 1, 2021 · 0 comments
Open

ASAN detects memory leak in PARSE_SCFG_STRING #1

MasterAler opened this issue Apr 1, 2021 · 0 comments

Comments

@MasterAler
Copy link

Что делал:

extern "C" {
// clang-format off
#define SCFG_APP_CONFIG(XX)                                                    \
XX((input),         SCFG_STRING, 'i', SCFG_NO_DEFAULT, "input video path")     \
/**/
// clang-format on
#include "scfg/scfg.h"
}

int main(int argc, char *argv[])
{  
// init config
if (!scfg_init(argc, argv))
    exit(1);
return 0;
}           

Собрал c ASAN, получаю:

=================================================================
==10000==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 13 byte(s) in 1 object(s) allocated from:
    #0 0x7f0ed8af6538 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x77538)
    #1 0x5643b445cfec in scfg_parse_argv bazel-out/k8-opt/bin/external/com_github_cdump_scfg/_virtual_includes/scfg/scfg/scfg.h:257
    #2 0x5643b445d3db in scfg_init bazel-out/k8-opt/bin/external/com_github_cdump_scfg/_virtual_includes/scfg/scfg/scfg.h:386
    #3 0x5643b445ddc2 in main video-detector/tools/turntable.cc:21
    #4 0x7f0ed794dbf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
SUMMARY: AddressSanitizer: 13 byte(s) leaked in 1 allocation(s).

Ругается на scfg/scfg.h:36

#define PARSE_SCFG_STRING(name, val) cfg.name = strdup(val ? val : "")

Предложения: не клонировать строку.

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

1 participant