[ovs-dev] [netdev 01/27] dpif-linux: Fix theoretical memory leak on error path.

Ben Pfaff blp at nicira.com
Thu Aug 1 21:29:24 UTC 2013


If a notification is bigger than 4 kB (I doubt it one would be), then the
lack of ofpbuf_uninit() would cause a memory leak.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/dpif-linux.c |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c
index 27c622a..1b97410 100644
--- a/lib/dpif-linux.c
+++ b/lib/dpif-linux.c
@@ -799,19 +799,21 @@ dpif_linux_port_poll(const struct dpif *dpif_, char **devnamep)
                     VLOG_DBG("port_changed: dpif:%s vport:%s cmd:%"PRIu8,
                              dpif->dpif.full_name, vport.name, vport.cmd);
                     *devnamep = xstrdup(vport.name);
+                    ofpbuf_uninit(&buf);
                     return 0;
-                } else {
-                    continue;
                 }
             }
-        } else if (error == EAGAIN) {
-            return EAGAIN;
+        } else if (error != EAGAIN) {
+            VLOG_WARN_RL(&rl, "error reading or parsing netlink (%s)",
+                         ovs_strerror(error));
+            nl_sock_drain(dpif->port_notifier);
+            error = ENOBUFS;
         }
 
-        VLOG_WARN_RL(&rl, "error reading or parsing netlink (%s)",
-                     ovs_strerror(error));
-        nl_sock_drain(dpif->port_notifier);
-        return ENOBUFS;
+        ofpbuf_uninit(&buf);
+        if (error) {
+            return error;
+        }
     }
 }
 
-- 
1.7.10.4




More information about the dev mailing list