diff mbox series

[ovs-dev,v2,1/2] controller: do not allocate iface name twice in if_status_mgr module

Message ID 8e55a5fc3f13de2ec39b02526e6bf6d031e88b76.1632242162.git.lorenzo.bianconi@redhat.com
State Superseded
Headers show
Series add memory accounting for if_status_mgr module | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_ovn-kubernetes success github build: passed
ovsrobot/github-robot-_Build_and_Test fail github build: failed

Commit Message

Lorenzo Bianconi Sept. 21, 2021, 4:37 p.m. UTC
Rely on shash_add_nocopy instead of shash_add in ovs_iface_create in
order to avoid allocating iface_id twice.

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 controller/if-status.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/controller/if-status.c b/controller/if-status.c
index b5a4025fc..00f826c50 100644
--- a/controller/if-status.c
+++ b/controller/if-status.c
@@ -344,7 +344,7 @@  ovs_iface_create(struct if_status_mgr *mgr, const char *iface_id,
 
     VLOG_DBG("Interface %s create.", iface_id);
     iface->id = xstrdup(iface_id);
-    shash_add(&mgr->ifaces, iface_id, iface);
+    shash_add_nocopy(&mgr->ifaces, iface->id, iface);
     ovs_iface_set_state(mgr, iface, state);
     return iface;
 }
@@ -355,7 +355,10 @@  ovs_iface_destroy(struct if_status_mgr *mgr, struct ovs_iface *iface)
     VLOG_DBG("Interface %s destroy: state %s", iface->id,
              if_state_names[iface->state]);
     hmapx_find_and_delete(&mgr->ifaces_per_state[iface->state], iface);
-    shash_find_and_delete(&mgr->ifaces, iface->id);
+    struct shash_node *node = shash_find(&mgr->ifaces, iface->id);
+    if (node) {
+        shash_steal(&mgr->ifaces, node);
+    }
     free(iface->id);
     free(iface);
 }