From 765d08087bf422c821556400a68e1fb4868f85f3 Mon Sep 17 00:00:00 2001 From: Jose Bollo Date: Wed, 6 Feb 2019 16:11:42 +0100 Subject: [PATCH] wgtpkg-unit: Fix Segmentation fault This fixes a segmentation fault raised when uninstalling a widget. This regression was introduced by the commit f8b0495. Bug-AGL: SPEC-2144 Change-Id: Ie10eb97a4d2f2663d73f83b210ef2b17717ed2e6 Signed-off-by: Jose Bollo --- src/wgtpkg-unit.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/wgtpkg-unit.c b/src/wgtpkg-unit.c index cca718f..9f14346 100644 --- a/src/wgtpkg-unit.c +++ b/src/wgtpkg-unit.c @@ -382,10 +382,14 @@ static int add_metadata(struct json_object *jdesc, const struct unitconf *conf) n = json_object_array_length(targets); for (i = 0 ; i < n ; i++) { targ = json_object_array_get_idx(targets, i); - port = conf->port(); - if (port < 0) - return port; - sprintf(portstr, "%d", port); + if (!conf->port) + strcpy(portstr, "0"); + else { + port = conf->port ? conf->port() : 0; + if (port < 0) + return port; + sprintf(portstr, "%d", port); + } if (!j_add_string_m(targ, "#metatarget.http-port", portstr)) return -1; } -- 2.16.6