]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: plug memory leak
authorEric Blake <eblake@redhat.com>
Tue, 2 Aug 2011 22:21:37 +0000 (16:21 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 2 Aug 2011 22:39:02 +0000 (16:39 -0600)
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

index 03a9e1adcdd2e307118dbaf690ceecede25f8fd3..2e2a6a01d34987f037a234d43eb8deddcca8d6e5 100644 (file)
@@ -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;