diff --git a/net/respondd-module-wifi/src/neighbours.c b/net/respondd-module-wifi/src/neighbours.c index f097908..fbbcf40 100644 --- a/net/respondd-module-wifi/src/neighbours.c +++ b/net/respondd-module-wifi/src/neighbours.c @@ -13,10 +13,8 @@ static int station_neighbours_handler(struct nl_msg *msg, void *arg) { struct json_object *neighbour, *json = (struct json_object *) arg; neighbour = json_object_new_object(); - if (!neighbour) { - //TODO why needed? : json_object_put(result); + if (!neighbour) goto abort; - } struct nlattr *tb[NL80211_ATTR_MAX + 1]; @@ -27,13 +25,16 @@ static int station_neighbours_handler(struct nl_msg *msg, void *arg) { if (!station_info) { fputs("respondd-module-wifi: station data missing in netlink message\n", stderr); + json_object_put(neighbour); goto abort; } char mac_addr[20]; - if (!tb[NL80211_ATTR_MAC]) + if (!tb[NL80211_ATTR_MAC]) { + json_object_put(neighbour); goto abort; + } mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC])); int rem; @@ -75,8 +76,10 @@ bool get_neighbours(struct json_object *result, int ifx) { neighbours = json_object_new_object(); if (!neighbours) return false; - if(!nl_send_dump(station_neighbours_handler, neighbours, NL80211_CMD_GET_STATION, ifx)) + if(!nl_send_dump(station_neighbours_handler, neighbours, NL80211_CMD_GET_STATION, ifx)) { + json_object_put(neighbours); return false; + } json_object_object_add(result, "neighbours", neighbours); return true; diff --git a/net/respondd-module-wifi/src/respondd.c b/net/respondd-module-wifi/src/respondd.c index 03fe015..212e1c0 100644 --- a/net/respondd-module-wifi/src/respondd.c +++ b/net/respondd-module-wifi/src/respondd.c @@ -21,12 +21,14 @@ static struct json_object *respondd_provider_statistics(void) { wireless = json_object_new_array(); if (!wireless) { - //TODO why needed? : json_object_put(result); + json_object_put(result); return NULL; } clients = json_object_new_object(); if (!clients) { + json_object_put(wireless); + json_object_put(result); return NULL; } @@ -83,7 +85,7 @@ static struct json_object *respondd_provider_neighbours(void) { wireless = json_object_new_object(); if (!wireless) { - //TODO why needed? : json_object_put(result); + json_object_put(result); return NULL; } @@ -98,8 +100,10 @@ static struct json_object *respondd_provider_neighbours(void) { if (!station) goto next_neighbours; - if (!get_neighbours(station, ifaces->ifx)) + if (!get_neighbours(station, ifaces->ifx)) { + json_object_put(station); goto next_neighbours; + } if (ifaces->frequency) json_object_object_add(station, "frequency", json_object_new_int(ifaces->frequency));