Skip to content

Commit

Permalink
Merge pull request #36 from ecmwf/fix/leak-fdb-read
Browse files Browse the repository at this point in the history
FDB::read memory leak
  • Loading branch information
simondsmart authored Sep 18, 2024
2 parents 5f18229 + 510fe25 commit 0d5741d
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/fdb5/api/FDB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include "eckit/message/Message.h"
#include "eckit/message/Reader.h"

#include "eckit/system/Plugin.h"
#include "eckit/system/LibraryManager.h"

#include "metkit/hypercube/HyperCubePayloaded.h"

#include "fdb5/LibFdb5.h"
Expand All @@ -34,6 +31,8 @@
#include "fdb5/message/MessageDecoder.h"
#include "fdb5/types/Type.h"

#include <memory>

namespace fdb5 {

//----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -154,21 +153,20 @@ class ListElementDeduplicator : public metkit::hypercube::Deduplicator<ListEleme
};

eckit::DataHandle* FDB::read(const eckit::URI& uri) {
FieldLocation* loc = FieldLocationFactory::instance().build(uri.scheme(), uri);
return loc->dataHandle();
auto location = std::unique_ptr<FieldLocation>(FieldLocationFactory::instance().build(uri.scheme(), uri));
return location->dataHandle();
}

eckit::DataHandle* FDB::read(const std::vector<eckit::URI>& uris, bool sorted) {
HandleGatherer result(sorted);

for (const eckit::URI& uri : uris) {
FieldLocation* loc = FieldLocationFactory::instance().build(uri.scheme(), uri);
result.add(loc->dataHandle());
delete loc;
auto location = std::unique_ptr<FieldLocation>(FieldLocationFactory::instance().build(uri.scheme(), uri));
result.add(location->dataHandle());
}

return result.dataHandle();
}


eckit::DataHandle* FDB::read(ListIterator& it, bool sorted) {
eckit::Timer timer;
Expand Down

0 comments on commit 0d5741d

Please sign in to comment.