[lxc-devel] [PATCH] coverity 1026198: remove unnecessary NULL check

Dwight Engen dwight.engen at oracle.com
Wed Oct 30 17:50:26 UTC 2013


c->lxc_conf cannot be NULL in this case since the call sequence
c->save_config()
  c->load_config()
    load_config_locked()
which is done before this check will allocate it or fail

Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
---
 src/lxc/lxccontainer.c | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 680b536..1254dc0 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -1128,24 +1128,22 @@ static bool lxcapi_create(struct lxc_container *c, const char *t,
 		goto out;
 	}
 
-	if (c->lxc_conf) {
-		/*
-		 * either template or rootfs.path should be set.
-		 * if both template and rootfs.path are set, template is setup as rootfs.path.
-		 * container is already created if we have a config and rootfs.path is accessible
-		 */
-		if (!c->lxc_conf->rootfs.path && !tpath)
-			/* no template passed in and rootfs does not exist: error */
-			goto out;
-		if (c->lxc_conf->rootfs.path && access(c->lxc_conf->rootfs.path, F_OK) != 0)
-			/* rootfs passed into configuration, but does not exist: error */
-			goto out;
-		if (lxcapi_is_defined(c) && c->lxc_conf->rootfs.path && !tpath) {
-			/* Rootfs already existed, user just wanted to save the
-			 * loaded configuration */
-			ret = true;
-			goto out;
-		}
+	/*
+	 * either template or rootfs.path should be set.
+	 * if both template and rootfs.path are set, template is setup as rootfs.path.
+	 * container is already created if we have a config and rootfs.path is accessible
+	 */
+	if (!c->lxc_conf->rootfs.path && !tpath)
+		/* no template passed in and rootfs does not exist: error */
+		goto out;
+	if (c->lxc_conf->rootfs.path && access(c->lxc_conf->rootfs.path, F_OK) != 0)
+		/* rootfs passed into configuration, but does not exist: error */
+		goto out;
+	if (lxcapi_is_defined(c) && c->lxc_conf->rootfs.path && !tpath) {
+		/* Rootfs already existed, user just wanted to save the
+		 * loaded configuration */
+		ret = true;
+		goto out;
 	}
 
 	/* Mark that this container is being created */
-- 
1.8.3.1





More information about the lxc-devel mailing list