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 in Kokkos::initialize #1194

Closed
ibaned opened this issue Oct 27, 2017 · 1 comment
Closed

Memory leak in Kokkos::initialize #1194

ibaned opened this issue Oct 27, 2017 · 1 comment
Assignees
Labels
Bug Broken / incorrect code; it could be Kokkos' responsibility, or others’ (e.g., Trilinos)
Milestone

Comments

@ibaned
Copy link
Contributor

ibaned commented Oct 27, 2017

Here is the snippet, the C string num1_only never gets freed/deleted:

        char* num1 = strchr(arg[iarg],'=')+1;
        char* num2 = strpbrk(num1,",");
        int num1_len = num2==NULL?strlen(num1):num2-num1;
        char* num1_only = new char[num1_len+1];
        strncpy(num1_only,num1,num1_len);
        num1_only[num1_len]=0;

        if(!Impl::is_unsigned_int(num1_only) || (strlen(num1_only)==0)) {
          Impl::throw_runtime_exception("Error: expecting an integer number after command line argument '--kokkos-ndevices'. Raised by Kokkos::initialize(int narg, char* argc[]).");
        }
        if((strncmp(arg[iarg],"--kokkos-ndevices",17) == 0) || !kokkos_ndevices_found)
          ndevices = atoi(num1_only);

Why are we, in a modern C++11 code, calling things like strpbrk and raw new in non-performance-critical code??

I'll submit a PR to just call delete in a moment, but the real fix is to get all of this C-style code replaced with std::string.

More importantly, we should incorporate Valgrind into Kokkos testing.

@ibaned ibaned added the Bug Broken / incorrect code; it could be Kokkos' responsibility, or others’ (e.g., Trilinos) label Oct 27, 2017
@ibaned ibaned self-assigned this Oct 27, 2017
ibaned added a commit that referenced this issue Oct 27, 2017
@mhoemmen
Copy link
Contributor

but the real fix is to get all of this C-style code replaced with std::string.

+1 (more like +N)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Broken / incorrect code; it could be Kokkos' responsibility, or others’ (e.g., Trilinos)
Projects
None yet
Development

No branches or pull requests

3 participants