Skip to content

Commit

Permalink
coverity: fix dns_sd.c Resource leak
Browse files Browse the repository at this point in the history
CID 355432 (#2 of 2): Resource leak (RESOURCE_LEAK)
3. leaked_storage: Variable ddata going out of scope leaks the storage it points to.

Ensure we free anything that was allocated

Signed-off-by: Robin Getz <robin.getz@analog.com>
  • Loading branch information
rgetz committed Apr 3, 2020
1 parent 332ecdb commit e284750
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dns_sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,13 @@ int dnssd_context_scan(struct iio_scan_backend_context *ctx,
ret = dnssd_find_hosts(&ddata);

/* if we return an error when no devices are found, then other scans will fail */
if (ret == -ENXIO)
return 0;
if (ret == -ENXIO) {
ret = 0;
goto fail;
}

if (ret < 0)
return ret;
goto fail;

for (ndata = ddata; ndata->next != NULL; ndata = ndata->next) {
info = iio_scan_result_add(scan_result, 1);
Expand All @@ -271,6 +273,7 @@ int dnssd_context_scan(struct iio_scan_backend_context *ctx,
}
}

fail:
dnssd_free_all_discovery_data(ddata);
return ret;
}
Expand Down

0 comments on commit e284750

Please sign in to comment.