[PATCH 16/3] util: plug memory leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Leak detected by Coverity; only possible on unlikely ptsname_r
failure.  Additionally, the man page for ptsname_r states that
failure is merely non-zero, not necessarily -1.

* src/util/util.c (virFileOpenTtyAt): Avoid leak on ptsname_r
failure.
---
 src/util/util.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/util/util.c b/src/util/util.c
index 03a9e1a..2e2a6a0 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1126,8 +1126,10 @@ int virFileOpenTtyAt(const char *ptmx,
             goto cleanup;
         }

-        if (ptsname_r(*ttymaster, *ttyName, PATH_MAX) < 0)
+        if (ptsname_r(*ttymaster, *ttyName, PATH_MAX) != 0) {
+            VIR_FREE(*ttyName);
             goto cleanup;
+        }
     }

     rc = 0;
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]