Skip to content

Commit

Permalink
Fix undefined behavior in verbose logging of deregister task
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Dec 18, 2023
1 parent a62b643 commit 34c2e48
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
13 changes: 11 additions & 2 deletions include/openPMD/IO/IOTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "openPMD/backend/Attribute.hpp"
#include "openPMD/backend/ParsePreference.hpp"

#include <cstddef>
#include <map>
#include <memory>
#include <string>
Expand Down Expand Up @@ -680,15 +681,23 @@ template <>
struct OPENPMDAPI_EXPORT Parameter<Operation::DEREGISTER>
: public AbstractParameter
{
Parameter() = default;
Parameter(Parameter const &) : AbstractParameter()
Parameter(void const *ptr_in) : former_parent(ptr_in)
{}

Parameter(Parameter const &) = default;
Parameter(Parameter &&) = default;

Parameter &operator=(Parameter const &) = default;
Parameter &operator=(Parameter &&) = default;

std::unique_ptr<AbstractParameter> to_heap() && override
{
return std::make_unique<Parameter<Operation::DEREGISTER>>(
std::move(*this));
}

// Just for verbose logging.
void const *former_parent = nullptr;
};

/** @brief Self-contained description of a single IO operation.
Expand Down
6 changes: 5 additions & 1 deletion src/IO/AbstractIOHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,11 @@ std::future<void> AbstractIOHandlerImpl::flush()
auto &parameter = deref_dynamic_cast<Parameter<O::DEREGISTER>>(
i.parameter.get());
writeToStderr(
"[", i.writable->parent, "->", i.writable, "] DEREGISTER");
"[",
parameter.former_parent,
"->",
i.writable,
"] DEREGISTER");
deregister(i.writable, parameter);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/Writable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Writable::~Writable()
* remove references to this object from internal data structures.
*/
IOHandler->value()->enqueue(
IOTask(this, Parameter<Operation::DEREGISTER>()));
IOTask(this, Parameter<Operation::DEREGISTER>(parent)));
}

void Writable::seriesFlush(std::string backendConfig)
Expand Down

0 comments on commit 34c2e48

Please sign in to comment.