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 as a result of using h5::open to create h5::pt_t #80

Open
ValentinKroner opened this issue Jul 11, 2023 · 0 comments
Open

Comments

@ValentinKroner
Copy link

As the title says, a tiny amount of memory is allocated and not released on using h5::open to get an instance of h5::pt_t.
The memory is not released when the pointer runs out of scope.

Minimal example code:

#include <iostream>
#include <thread>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wpedantic"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wswitch"
#pragma GCC diagnostic ignored "-Wreorder"
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#include <h5cpp/all>
#pragma GCC diagnostic pop


int main(int ac, char *av[]) {

  (void) ac;
  (void) av;

  std::cout << "hello there" << std::endl;

  //Scope this entire thing to make sure everything is destroyed at the end
  {
    int n_calls = 10000000;
    unsigned int dim = 4;


    std::string file_path = "./test.hdf5";

    h5::fd_t handle = h5::create(file_path, H5F_ACC_EXCL);

    {
      h5::pt_t pt = h5::create<std::uint16_t>(
          handle, "test",
          h5::max_dims{H5S_UNLIMITED, dim, dim},
          h5::chunk{1, dim, dim});
    }

    for (int i = 0; i < n_calls; i++) {

      //this element is problematic, as a small bit of memory is retained even when the handle is destroyed at the
      //end of the for loop scope
      h5::pt_t pt = h5::open(handle, "test");

      std::vector<float> demo_frame_float = std::vector<float>(dim * dim, 76);

      h5::append(pt, demo_frame_float);
    }
  }

  std::cout << "done writing, time to sleep" << std::endl;

  //sleep to allow for inspection of system memory after the actual write
  std::this_thread::sleep_for(std::chrono::seconds(1000000));
}

The problem is not visible in valgrind, but can be observed in top under ubuntu when a lot of calls are performed.
In the the above code, the problem does not occur when the open call is lifted up from the for loop, and the pointer is reused.
OS version was 22.04, compiler was gcc12.1.0

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