]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
uml: Remove PATH_MAX sized stack allocation from /proc parsing code
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sun, 3 Apr 2011 09:21:31 +0000 (11:21 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 5 Apr 2011 07:13:29 +0000 (09:13 +0200)
src/uml/uml_driver.c

index e2bd5f25820cadd7d190043b1b6db276e07303d7..33849a07e187515a3d3ac5b393925f6aa602e1d9 100644 (file)
@@ -1036,21 +1036,25 @@ static char *umlGetCapabilities(virConnectPtr conn) {
 
 
 
-static int umlGetProcessInfo(unsigned long long *cpuTime, int pid) {
-    char proc[PATH_MAX];
+static int umlGetProcessInfo(unsigned long long *cpuTime, int pid)
+{
+    char *proc;
     FILE *pidinfo;
     unsigned long long usertime, systime;
 
-    if (snprintf(proc, sizeof(proc), "/proc/%d/stat", pid) >= (int)sizeof(proc)) {
+    if (virAsprintf(&proc, "/proc/%d/stat", pid) < 0) {
         return -1;
     }
 
     if (!(pidinfo = fopen(proc, "r"))) {
         /* VM probably shut down, so fake 0 */
         *cpuTime = 0;
+        VIR_FREE(proc);
         return 0;
     }
 
+    VIR_FREE(proc);
+
     if (fscanf(pidinfo, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu", &usertime, &systime) != 2) {
         umlDebug("not enough arg");
         VIR_FORCE_FCLOSE(pidinfo);