Skip to content

Commit 88716ce

Browse files
committed
Fill missing fields in BpfObject's move constructor
1 parent 003495e commit 88716ce

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/core/bpf_object.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "bpf_program.h"
55
#include "utils/struct_parser.h"
66
#include <cerrno>
7+
#include <utility>
78

89
BpfObject::BpfObject(std::string object_path, py::dict structs)
910
: obj_(nullptr), object_path_(std::move(object_path)), loaded_(false),
@@ -22,9 +23,13 @@ BpfObject::~BpfObject() {
2223
}
2324

2425
BpfObject::BpfObject(BpfObject &&other) noexcept
25-
: obj_(other.obj_), object_path_(std::move(other.object_path_)),
26-
loaded_(other.loaded_), prog_cache_(std::move(other.prog_cache_)),
27-
maps_cache_(std::move(other.maps_cache_)) {
26+
: obj_(std::exchange(other.obj_, nullptr)),
27+
object_path_(std::move(other.object_path_)),
28+
loaded_(std::exchange(other.loaded_, false)),
29+
maps_cache_(std::move(other.maps_cache_)),
30+
prog_cache_(std::move(other.prog_cache_)),
31+
struct_defs_(std::move(other.struct_defs_)),
32+
struct_parser_(std::move(other.struct_parser_)) {
2833

2934
other.obj_ = nullptr;
3035
other.loaded_ = false;
@@ -38,14 +43,13 @@ BpfObject &BpfObject::operator=(BpfObject &&other) noexcept {
3843
bpf_object__close(obj_);
3944
}
4045

41-
obj_ = other.obj_;
46+
obj_ = std::exchange(other.obj_, nullptr);
4247
object_path_ = std::move(other.object_path_);
43-
loaded_ = other.loaded_;
44-
prog_cache_ = std::move(other.prog_cache_);
48+
loaded_ = std::exchange(other.loaded_, false);
4549
maps_cache_ = std::move(other.maps_cache_);
46-
47-
other.obj_ = nullptr;
48-
other.loaded_ = false;
50+
prog_cache_ = std::move(other.prog_cache_);
51+
struct_defs_ = std::move(other.struct_defs_);
52+
struct_parser_ = std::move(other.struct_parser_);
4953
}
5054
return *this;
5155
}

0 commit comments

Comments
 (0)