[Libguestfs] [PATCH 53/67] list-filesystems: Don't fail if there are no filesystems found (RHBZ#995711).

Richard W.M. Jones rjones at redhat.com
Sat Aug 24 11:04:53 UTC 2013


From: "Richard W.M. Jones" <rjones at redhat.com>

list-filesystems was returning NULL (but not setting an error) if no
filesystems were found.  Instead return an empty list.

(cherry picked from commit f1d2934216d3fca0501946c8ae0e5c7cd370e6b6)
---
 src/listfs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/listfs.c b/src/listfs.c
index eb4019d..bd3ee71 100644
--- a/src/listfs.c
+++ b/src/listfs.c
@@ -46,7 +46,7 @@ char **
 guestfs__list_filesystems (guestfs_h *g)
 {
   size_t i;
-  char **ret = NULL;
+  char **ret;
   size_t ret_size = 0;
   const char *lvm2[] = { "lvm2", NULL };
   const char *ldm[] = { "ldm", NULL };
@@ -58,6 +58,13 @@ guestfs__list_filesystems (guestfs_h *g)
   CLEANUP_FREE_STRING_LIST char **ldmvols = NULL;
   CLEANUP_FREE_STRING_LIST char **ldmparts = NULL;
 
+  /* We need to initialize this with an empty list so that if there
+   * are no filesystems at all, we return an empty list (not NULL).
+   * See also add_vfs function below.
+   */
+  ret = safe_malloc (g, sizeof (char *));
+  ret[0] = NULL;
+
   /* Look to see if any devices directly contain filesystems
    * (RHBZ#590167).  However vfs-type will fail to tell us anything
    * useful about devices which just contain partitions, so we also
-- 
1.8.3.1




More information about the Libguestfs mailing list