]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: numa: Catch readdir errors in virNumaGetPages
authorPeter Krempa <pkrempa@redhat.com>
Mon, 23 Jun 2014 07:10:04 +0000 (09:10 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 23 Jun 2014 12:00:10 +0000 (14:00 +0200)
Don't return possibly incomplete result if virDirRead fails.

src/util/virnuma.c

index c8e7f40ddfd05a12dbb5a0f8516d3ed8b4520757..9cf5a75a9a71abde10091cf5c41f0060f80a020c 100644 (file)
@@ -728,6 +728,7 @@ virNumaGetPages(int node,
     int ret = -1;
     char *path = NULL;
     DIR *dir = NULL;
+    int direrr;
     struct dirent *entry;
     unsigned int *tmp_size = NULL, *tmp_avail = NULL, *tmp_free = NULL;
     unsigned int ntmp = 0;
@@ -768,7 +769,7 @@ virNumaGetPages(int node,
         goto cleanup;
     }
 
-    while (virDirRead(dir, &entry, path) > 0) {
+    while ((direrr = virDirRead(dir, &entry, path)) > 0) {
         const char *page_name = entry->d_name;
         unsigned int page_size, page_avail = 0, page_free = 0;
         char *end;
@@ -805,6 +806,9 @@ virNumaGetPages(int node,
         ntmp++;
     }
 
+    if (direrr < 0)
+        goto cleanup;
+
     /* Just to produce nice output, sort the arrays by increasing page size */
     do {
         exchange = false;