summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Bollo <jose.bollo@iot.bzh>2019-02-06 16:11:42 +0100
committerJose Bollo <jose.bollo@iot.bzh>2019-02-06 16:16:34 +0100
commit765d08087bf422c821556400a68e1fb4868f85f3 (patch)
tree115323368acb46e82b3f7a00dad966c1fd29f29b
parentd0cb2a7a1e068a38b4a0c3216ccdbce0e33ecffb (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;
}