Use local variable to stop memory leak.
I've change the urls variable to be a local, instead of manually allocating it all the time. This is only used locally and was causing a memory leak because FreeUPNPUrls gave the impression it free it. 1. FreeUPNPUrls doesn't free the pointer passed in, that's up to caller. 2. The second if(!urls) produced dead code as we checked the pointer just after allocation.
This commit is contained in:
parent
79de2eaae7
commit
767bfec8b6
2 changed files with 10 additions and 23 deletions
|
@ -71,7 +71,7 @@
|
||||||
<constant name="IGD_STATUS_HTTP_EMPTY" value="2" enum="IGDStatus">
|
<constant name="IGD_STATUS_HTTP_EMPTY" value="2" enum="IGDStatus">
|
||||||
Empty HTTP response.
|
Empty HTTP response.
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="IGD_STATUS_NO_URLS" value="3" enum="IGDStatus">
|
<constant name="IGD_STATUS_NO_URLS" value="3" enum="IGDStatus" deprecated="This value is no longer used.">
|
||||||
Returned response contained no URLs.
|
Returned response contained no URLs.
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="IGD_STATUS_NO_IGD" value="4" enum="IGDStatus">
|
<constant name="IGD_STATUS_NO_IGD" value="4" enum="IGDStatus">
|
||||||
|
@ -86,7 +86,7 @@
|
||||||
<constant name="IGD_STATUS_INVALID_CONTROL" value="7" enum="IGDStatus">
|
<constant name="IGD_STATUS_INVALID_CONTROL" value="7" enum="IGDStatus">
|
||||||
Invalid control.
|
Invalid control.
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="IGD_STATUS_MALLOC_ERROR" value="8" enum="IGDStatus">
|
<constant name="IGD_STATUS_MALLOC_ERROR" value="8" enum="IGDStatus" deprecated="This value is no longer used.">
|
||||||
Memory allocation error.
|
Memory allocation error.
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="IGD_STATUS_UNKNOWN_ERROR" value="9" enum="IGDStatus">
|
<constant name="IGD_STATUS_UNKNOWN_ERROR" value="9" enum="IGDStatus">
|
||||||
|
|
|
@ -121,33 +121,20 @@ void UPNP::parse_igd(Ref<UPNPDevice> dev, UPNPDev *devlist) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UPNPUrls *urls = (UPNPUrls *)malloc(sizeof(struct UPNPUrls));
|
struct UPNPUrls urls = {};
|
||||||
|
|
||||||
if (!urls) {
|
|
||||||
dev->set_igd_status(UPNPDevice::IGD_STATUS_MALLOC_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IGDdatas data;
|
struct IGDdatas data;
|
||||||
|
|
||||||
memset(urls, 0, sizeof(struct UPNPUrls));
|
|
||||||
|
|
||||||
parserootdesc(xml, size, &data);
|
parserootdesc(xml, size, &data);
|
||||||
free(xml);
|
free(xml);
|
||||||
xml = nullptr;
|
xml = nullptr;
|
||||||
|
|
||||||
GetUPNPUrls(urls, &data, dev->get_description_url().utf8().get_data(), 0);
|
GetUPNPUrls(&urls, &data, dev->get_description_url().utf8().get_data(), 0);
|
||||||
|
|
||||||
if (!urls) {
|
|
||||||
dev->set_igd_status(UPNPDevice::IGD_STATUS_NO_URLS);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char addr[16];
|
char addr[16];
|
||||||
int i = UPNP_GetValidIGD(devlist, urls, &data, (char *)&addr, 16);
|
int i = UPNP_GetValidIGD(devlist, &urls, &data, (char *)&addr, 16);
|
||||||
|
|
||||||
if (i != 1) {
|
if (i != 1) {
|
||||||
FreeUPNPUrls(urls);
|
FreeUPNPUrls(&urls);
|
||||||
|
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -165,18 +152,18 @@ void UPNP::parse_igd(Ref<UPNPDevice> dev, UPNPDev *devlist) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (urls->controlURL[0] == '\0') {
|
if (urls.controlURL[0] == '\0') {
|
||||||
FreeUPNPUrls(urls);
|
FreeUPNPUrls(&urls);
|
||||||
dev->set_igd_status(UPNPDevice::IGD_STATUS_INVALID_CONTROL);
|
dev->set_igd_status(UPNPDevice::IGD_STATUS_INVALID_CONTROL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->set_igd_control_url(urls->controlURL);
|
dev->set_igd_control_url(urls.controlURL);
|
||||||
dev->set_igd_service_type(data.first.servicetype);
|
dev->set_igd_service_type(data.first.servicetype);
|
||||||
dev->set_igd_our_addr(addr);
|
dev->set_igd_our_addr(addr);
|
||||||
dev->set_igd_status(UPNPDevice::IGD_STATUS_OK);
|
dev->set_igd_status(UPNPDevice::IGD_STATUS_OK);
|
||||||
|
|
||||||
FreeUPNPUrls(urls);
|
FreeUPNPUrls(&urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
int UPNP::upnp_result(int in) {
|
int UPNP::upnp_result(int in) {
|
||||||
|
|
Loading…
Reference in a new issue