summaryrefslogtreecommitdiff
path: root/Modules/nismodule.c
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1997-01-09 22:22:05 +0000
committerBarry Warsaw <barry@python.org>1997-01-09 22:22:05 +0000
commitc9921d840548c7e5f9efad1739021d066d203b43 (patch)
tree4d8c609e33f67052080a87f3900442ccc564ec7b /Modules/nismodule.c
parentbcfaab3495803840b5fadc5075ad12c59afd887c (diff)
downloadcpython-c9921d840548c7e5f9efad1739021d066d203b43.tar.gz
Nailed a couple of memory leaks, caught by Purify.
Diffstat (limited to 'Modules/nismodule.c')
-rw-r--r--Modules/nismodule.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/Modules/nismodule.c b/Modules/nismodule.c
index a00a0e6e17..586602699a 100644
--- a/Modules/nismodule.c
+++ b/Modules/nismodule.c
@@ -292,7 +292,7 @@ nis_maplist ()
nisresp_maplist *list;
char *dom;
CLIENT *cl, *clnt_create();
- char *server = "";
+ char *server = NULL;
int mapi = 0;
int err;
@@ -301,25 +301,32 @@ nis_maplist ()
return NULL;
}
- while (!strcmp("", server) && aliases[mapi].map != 0L) {
+ while (!server && aliases[mapi].map != 0L) {
yp_master (dom, aliases[mapi].map, &server);
mapi++;
}
- if (!strcmp("", server)) {
+ if (!server) {
PyErr_SetString(NisError, "No NIS master found for any map");
return NULL;
}
cl = clnt_create(server, YPPROG, YPVERS, "tcp");
if (cl == NULL) {
PyErr_SetString(NisError, clnt_spcreateerror(server));
- return NULL;
+ goto finally;
}
list = nisproc_maplist_2 (&dom, cl);
+ clnt_destroy(cl);
if (list == NULL)
- return NULL;
+ goto finally;
if (list->stat != NIS_TRUE)
- return NULL;
+ goto finally;
+
+ PyMem_DEL(server);
return list->maps;
+
+ finally:
+ PyMem_DEL(server);
+ return NULL;
}
static PyObject *
@@ -337,12 +344,14 @@ nis_maps (self, args)
if ((list = PyList_New(0)) == NULL)
return NULL;
for (maps = maps->next; maps; maps = maps->next) {
- if (PyList_Append (list, PyString_FromString (maps->map)) < 0)
+ PyObject *str = PyString_FromString(maps->map);
+ if (!str || PyList_Append(list, str) < 0)
{
Py_DECREF(list);
list = NULL;
break;
}
+ Py_DECREF(str);
}
/* XXX Shouldn't we free the list of maps now? */
return list;