Skip to content

Commit

Permalink
Fix a memory issue when storing an existing pointer
Browse files Browse the repository at this point in the history
This is required for the previou commit of caching injection results.
  • Loading branch information
kyechou committed Nov 22, 2023
1 parent 9be8e86 commit 557c0a8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/unique-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void UniqueStorage::reset() {

Candidates *UniqueStorage::store_candidates(Candidates *candidates) {
auto res = storage.candidates_store.insert(candidates);
if (!res.second) {
if (!res.second && candidates != *(res.first)) {
delete candidates;
candidates = *(res.first);
}
Expand All @@ -74,7 +74,7 @@ Candidates *UniqueStorage::store_candidates(Candidates *candidates) {

FIB *UniqueStorage::store_fib(FIB *fib) {
auto res = storage.fib_store.insert(fib);
if (!res.second) {
if (!res.second && fib != *(res.first)) {
delete fib;
fib = *(res.first);
}
Expand All @@ -83,7 +83,7 @@ FIB *UniqueStorage::store_fib(FIB *fib) {

Choices *UniqueStorage::store_choices(Choices *choices) {
auto res = storage.choices_store.insert(choices);
if (!res.second) {
if (!res.second && choices != *(res.first)) {
delete choices;
choices = *(res.first);
}
Expand All @@ -92,7 +92,7 @@ Choices *UniqueStorage::store_choices(Choices *choices) {

Packet *UniqueStorage::store_packet(Packet *packet) {
auto res = storage.pkt_store.insert(packet);
if (!res.second) {
if (!res.second && packet != *(res.first)) {
delete packet;
packet = *(res.first);
}
Expand All @@ -101,7 +101,7 @@ Packet *UniqueStorage::store_packet(Packet *packet) {

NodePacketHistory *UniqueStorage::store_node_pkt_hist(NodePacketHistory *nph) {
auto res = storage.node_pkt_hist_store.insert(nph);
if (!res.second) {
if (!res.second && nph != *(res.first)) {
delete nph;
nph = *(res.first);
}
Expand All @@ -110,7 +110,7 @@ NodePacketHistory *UniqueStorage::store_node_pkt_hist(NodePacketHistory *nph) {

PacketHistory *UniqueStorage::store_pkt_hist(PacketHistory *pkt_hist) {
auto res = storage.pkt_hist_store.insert(pkt_hist);
if (!res.second) {
if (!res.second && pkt_hist != *(res.first)) {
delete pkt_hist;
pkt_hist = *(res.first);
}
Expand All @@ -120,7 +120,7 @@ PacketHistory *UniqueStorage::store_pkt_hist(PacketHistory *pkt_hist) {
OpenflowUpdateState *
UniqueStorage::store_of_update_state(OpenflowUpdateState *update_state) {
auto res = storage.openflow_update_state_store.insert(update_state);
if (!res.second) {
if (!res.second && update_state != *(res.first)) {
delete update_state;
update_state = *(res.first);
}
Expand All @@ -129,7 +129,7 @@ UniqueStorage::store_of_update_state(OpenflowUpdateState *update_state) {

ReachCounts *UniqueStorage::store_reach_counts(ReachCounts *reach_counts) {
auto res = storage.reach_counts_store.insert(reach_counts);
if (!res.second) {
if (!res.second && reach_counts != *(res.first)) {
delete reach_counts;
reach_counts = *(res.first);
}
Expand All @@ -139,7 +139,7 @@ ReachCounts *UniqueStorage::store_reach_counts(ReachCounts *reach_counts) {
InjectionResult *
UniqueStorage::store_injection_result(InjectionResult *result) {
auto res = storage.injection_result_store.insert(result);
if (!res.second) {
if (!res.second && result != *(res.first)) {
delete result;
result = *(res.first);
}
Expand All @@ -149,7 +149,7 @@ UniqueStorage::store_injection_result(InjectionResult *result) {
InjectionResults *
UniqueStorage::store_injection_results(InjectionResults *results) {
auto res = storage.injection_results_store.insert(results);
if (!res.second) {
if (!res.second && results != *(res.first)) {
delete results;
results = *(res.first);
}
Expand Down

0 comments on commit 557c0a8

Please sign in to comment.