[CRIU] [PATCH 1/1] simplify the asprintf() failure handling in add_fsname_auto()

Oleg Nesterov oleg at redhat.com
Thu Apr 23 07:30:45 PDT 2015


Contrary to what I naively thought, the contents of fsauto_names
is undefined if asprintf(&fsauto_names) and this was fixed by
a052e0b60a33e6c94e "check return code of asprintf".

But we can simplify this code a bit. If we rely on return value from
asprintf(), we can simply nullify fsauto_names on failure and avoid
the assymetrical "return false".

Signed-off-by: Oleg Nesterov <oleg at redhat.com>
---
 mount.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/mount.c b/mount.c
index 1d41d82..de2dcd7 100644
--- a/mount.c
+++ b/mount.c
@@ -1410,11 +1410,8 @@ bool add_fsname_auto(const char *names)
 	else if (!old)
 		fsauto_names = xstrdup(names);
 	else {
-		fsauto_names = NULL;
-		if (asprintf(&fsauto_names, "%s,%s", old, names) < 0) {
-			fsauto_names = old;
-			return false;
-		}
+		if (asprintf(&fsauto_names, "%s,%s", old, names) < 0)
+			fsauto_names = NULL;
 	}
 
 	xfree(old);
-- 
1.5.5.1




More information about the CRIU mailing list