miniupnpcmodule.c: throw an exception in UPnP_discover()

fixes #521
This commit is contained in:
Thomas Bernard 2021-01-15 20:21:02 +01:00
parent ef03e1bc21
commit 2adcf3f432
No known key found for this signature in database
GPG Key ID: DB511043A31ACAAF
1 changed files with 16 additions and 8 deletions

View File

@ -3,7 +3,7 @@
* Project : miniupnp
* Author : Thomas BERNARD
* website : https://miniupnp.tuxfamily.org/
* copyright (c) 2007-2020 Thomas Bernard
* copyright (c) 2007-2021 Thomas Bernard
* This software is subjet to the conditions detailed in the
* provided LICENCE file. */
#include <Python.h>
@ -122,9 +122,9 @@ UPnPObject_dealloc(UPnPObject *self)
static PyObject *
UPnP_discover(UPnPObject *self)
{
struct UPNPDev * dev;
int i;
int error = 0;
PyObject *res = NULL;
if(self->devlist)
{
freeUPNPDevlist(self->devlist);
@ -137,13 +137,21 @@ UPnP_discover(UPnPObject *self)
(int)self->localport,
0/*ip v6*/,
2/* TTL */,
0/*error */);
&error);
Py_END_ALLOW_THREADS
/* Py_RETURN_NONE ??? */
for(dev = self->devlist, i = 0; dev; dev = dev->pNext)
i++;
res = Py_BuildValue("i", i);
return res;
if (self->devlist != NULL) {
struct UPNPDev * dev;
int i = 0;
for(dev = self->devlist; dev; dev = dev->pNext)
i++;
res = Py_BuildValue("i", i);
return res;
} else {
PyErr_SetString(PyExc_Exception, strupnperror(error));
return NULL;
}
}
static PyObject *