summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Bollo <jose.bollo@iot.bzh>2019-02-06 16:11:42 +0100
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2019-02-06 16:13:36 +0000
commit8e5fc40306a5698c43079ff048155a9811eec062 (patch)
treed19f5596054b17781f363a49ba9caec309900777
parent728c66530f2b3c1a6cbfc905bae93cd72d6cf42d (diff)
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 <jose.bollo@iot.bzh>
-rw-r--r--src/wgtpkg-unit.c12
1 files 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;
}