From ed5ee4d4c3444cbf51ea84a13d484629d3795186 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 26 Mar 2018 15:03:21 +0300 Subject: [PATCH] shared/shell: Don't allocate any data if env value is NULL If value is NULL there is no point in allocating any data if value is NULL since bt_shell_get_env would return NULL anyway, also this makes sure the existing value is freed which means passing NULL can remove an env like it was intended. --- src/shared/shell.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/shared/shell.c b/src/shared/shell.c index b503c6628..367e25545 100644 --- a/src/shared/shell.c +++ b/src/shared/shell.c @@ -1145,6 +1145,8 @@ void bt_shell_set_env(const char *name, void *value) struct bt_shell_env *env; if (!data.envs) { + if (!value) + return; data.envs = queue_new(); goto done; } @@ -1153,6 +1155,10 @@ void bt_shell_set_env(const char *name, void *value) if (env) env_destroy(env); + /* Don't create an env if value is not set */ + if (!value) + return; + done: env = new0(struct bt_shell_env, 1); env->name = strdup(name); -- 2.47.3