summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Houghton <alastair@alastairs-place.net>2014-05-16 20:26:58 +0100
committerAlastair Houghton <alastair@alastairs-place.net>2014-05-16 20:26:58 +0100
commit93605f5bf0610864c9a093853b8b41ba844f8b91 (patch)
tree2e362d82b7bf0f3fbe541020fb6ebe984669bbb0
parent1d1a32655c6809e78e551fb5cd6bb74fd7d00722 (diff)
downloadnetifaces-git-93605f5bf0610864c9a093853b8b41ba844f8b91.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.c5
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;