diff options
author | Alastair Houghton <alastair@coriolis-systems.com> | 2014-05-16 20:26:58 +0100 |
---|---|---|
committer | Alastair Houghton <alastair@coriolis-systems.com> | 2014-05-16 20:26:58 +0100 |
commit | 594b7884adcb0e11640d58a9d1b58e77f485b788 (patch) | |
tree | 2e362d82b7bf0f3fbe541020fb6ebe984669bbb0 | |
parent | 8b3b32997e51ae35fd19b5c24f2483d4b243b9bc (diff) | |
download | netifaces-594b7884adcb0e11640d58a9d1b58e77f485b788.tar.gz |
Fixed a problem on Linux that meant that the gateways() method could crash if the routing table dump was interrupted.
-rw-r--r-- | netifaces.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/netifaces.c b/netifaces.c index e0f7dd2..6e09323 100644 --- a/netifaces.c +++ b/netifaces.c @@ -1482,9 +1482,9 @@ gateways (PyObject *self) /* This prevents a crash on PyPy */ defaults = PyDict_GetItemString (result, "default"); - msgbuf = pmsg = (struct routing_msg *)malloc (bufsize); + msgbuf = (struct routing_msg *)malloc (bufsize); - if (!pmsg) { + if (!msgbuf) { PyErr_NoMemory (); Py_DECREF (result); return NULL; @@ -1523,6 +1523,7 @@ gateways (PyObject *self) do { interrupted = 0; + pmsg = msgbuf; memset (pmsg, 0, sizeof (struct routing_msg)); pmsg->hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); pmsg->hdr.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST; |