diff mbox series

[ovs-dev,1/1] ovsdb-tool: fix memory leak while running "db-is-standalone" command

Message ID 1570437007-26356-1-git-send-email-damjan.skvarc@gmail.com
State Accepted
Commit 36e282f5c97891ee36f5ba71b017e8ee665b01d5
Headers show
Series [ovs-dev,1/1] ovsdb-tool: fix memory leak while running "db-is-standalone" command | expand

Commit Message

Damijan Skvarc Oct. 7, 2019, 8:30 a.m. UTC
problem is reported by valgrind while running functional tests:

==21043== 160 (88 direct, 72 indirect) bytes in 1 blocks are definitely lost in loss record 7 of 8
==21043==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==21043==    by 0x45EE2E: xmalloc (util.c:138)
==21043==    by 0x40CB81: ovsdb_log_open (log.c:270)
==21043==    by 0x406B4F: do_db_has_magic.isra.9 (ovsdb-tool.c:563)
==21043==    by 0x438670: ovs_cmdl_run_command__ (command-line.c:223)
==21043==    by 0x438720: ovs_cmdl_run_command (command-line.c:254)
==21043==    by 0x405A4C: main (ovsdb-tool.c:79)

problem was in do_db_has_magic() which opens log file which is never closed.

Signed-off-by: Damijan Skvarc <damjan.skvarc@gmail.com>
---
 ovsdb/ovsdb-tool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Ben Pfaff Oct. 7, 2019, 6:21 p.m. UTC | #1
On Mon, Oct 07, 2019 at 10:30:07AM +0200, Damijan Skvarc wrote:
> problem is reported by valgrind while running functional tests:
> 
> ==21043== 160 (88 direct, 72 indirect) bytes in 1 blocks are definitely lost in loss record 7 of 8
> ==21043==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==21043==    by 0x45EE2E: xmalloc (util.c:138)
> ==21043==    by 0x40CB81: ovsdb_log_open (log.c:270)
> ==21043==    by 0x406B4F: do_db_has_magic.isra.9 (ovsdb-tool.c:563)
> ==21043==    by 0x438670: ovs_cmdl_run_command__ (command-line.c:223)
> ==21043==    by 0x438720: ovs_cmdl_run_command (command-line.c:254)
> ==21043==    by 0x405A4C: main (ovsdb-tool.c:79)
> 
> problem was in do_db_has_magic() which opens log file which is never closed.
> 
> Signed-off-by: Damijan Skvarc <damjan.skvarc@gmail.com>

Applied to master, thanks.
aginwala March 19, 2020, 8:53 p.m. UTC | #2
Hi Ben:
Can you also backport this patch to 2.12 and 2.11 too?

On Mon, Oct 7, 2019 at 11:21 AM Ben Pfaff <blp@ovn.org> wrote:

> On Mon, Oct 07, 2019 at 10:30:07AM +0200, Damijan Skvarc wrote:
> > problem is reported by valgrind while running functional tests:
> >
> > ==21043== 160 (88 direct, 72 indirect) bytes in 1 blocks are definitely
> lost in loss record 7 of 8
> > ==21043==    at 0x4C2DB8F: malloc (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> > ==21043==    by 0x45EE2E: xmalloc (util.c:138)
> > ==21043==    by 0x40CB81: ovsdb_log_open (log.c:270)
> > ==21043==    by 0x406B4F: do_db_has_magic.isra.9 (ovsdb-tool.c:563)
> > ==21043==    by 0x438670: ovs_cmdl_run_command__ (command-line.c:223)
> > ==21043==    by 0x438720: ovs_cmdl_run_command (command-line.c:254)
> > ==21043==    by 0x405A4C: main (ovsdb-tool.c:79)
> >
> > problem was in do_db_has_magic() which opens log file which is never
> closed.
> >
> > Signed-off-by: Damijan Skvarc <damjan.skvarc@gmail.com>
>
> Applied to master, thanks.
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
Ben Pfaff March 19, 2020, 9:38 p.m. UTC | #3
OK, done.

On Thu, Mar 19, 2020 at 01:53:40PM -0700, aginwala wrote:
> Hi Ben:
> Can you also backport this patch to 2.12 and 2.11 too?
> 
> On Mon, Oct 7, 2019 at 11:21 AM Ben Pfaff <blp@ovn.org> wrote:
> 
> > On Mon, Oct 07, 2019 at 10:30:07AM +0200, Damijan Skvarc wrote:
> > > problem is reported by valgrind while running functional tests:
> > >
> > > ==21043== 160 (88 direct, 72 indirect) bytes in 1 blocks are definitely
> > lost in loss record 7 of 8
> > > ==21043==    at 0x4C2DB8F: malloc (in
> > /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> > > ==21043==    by 0x45EE2E: xmalloc (util.c:138)
> > > ==21043==    by 0x40CB81: ovsdb_log_open (log.c:270)
> > > ==21043==    by 0x406B4F: do_db_has_magic.isra.9 (ovsdb-tool.c:563)
> > > ==21043==    by 0x438670: ovs_cmdl_run_command__ (command-line.c:223)
> > > ==21043==    by 0x438720: ovs_cmdl_run_command (command-line.c:254)
> > > ==21043==    by 0x405A4C: main (ovsdb-tool.c:79)
> > >
> > > problem was in do_db_has_magic() which opens log file which is never
> > closed.
> > >
> > > Signed-off-by: Damijan Skvarc <damjan.skvarc@gmail.com>
> >
> > Applied to master, thanks.
> > _______________________________________________
> > dev mailing list
> > dev@openvswitch.org
> > https://mail.openvswitch.org/mailman/listinfo/ovs-dev
> >
diff mbox series

Patch

diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
index a8f3135..91662ca 100644
--- a/ovsdb/ovsdb-tool.c
+++ b/ovsdb/ovsdb-tool.c
@@ -562,7 +562,9 @@  do_db_has_magic(struct ovs_cmdl_context *ctx, const char *magic)
 
     check_ovsdb_error(ovsdb_log_open(filename, OVSDB_MAGIC"|"RAFT_MAGIC,
                                      OVSDB_LOG_READ_ONLY, -1, &log));
-    if (strcmp(ovsdb_log_get_magic(log), magic)) {
+    int cmp = strcmp(ovsdb_log_get_magic(log), magic);
+    ovsdb_log_close(log);
+    if (cmp) {
         exit(2);
     }
 }