Nailed a couple of memory leaks, caught by Purify. · pythoncapi/cpython@4bc9d39 · GitHub
Skip to content

Commit 4bc9d39

Browse files
committed
Nailed a couple of memory leaks, caught by Purify.
1 parent 4b76ba3 commit 4bc9d39

4 files changed

Lines changed: 25 additions & 8 deletions

File tree

Modules/grpmodule.c

Lines changed: 2 additions & 0 deletions

Modules/nismodule.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ nis_maplist ()
292292
nisresp_maplist *list;
293293
char *dom;
294294
CLIENT *cl, *clnt_create();
295-
char *server = "";
295+
char *server = NULL;
296296
int mapi = 0;
297297
int err;
298298

@@ -301,25 +301,32 @@ nis_maplist ()
301301
return NULL;
302302
}
303303

304-
while (!strcmp("", server) && aliases[mapi].map != 0L) {
304+
while (!server && aliases[mapi].map != 0L) {
305305
yp_master (dom, aliases[mapi].map, &server);
306306
mapi++;
307307
}
308-
if (!strcmp("", server)) {
308+
if (!server) {
309309
PyErr_SetString(NisError, "No NIS master found for any map");
310310
return NULL;
311311
}
312312
cl = clnt_create(server, YPPROG, YPVERS, "tcp");
313313
if (cl == NULL) {
314314
PyErr_SetString(NisError, clnt_spcreateerror(server));
315-
return NULL;
315+
goto finally;
316316
}
317317
list = nisproc_maplist_2 (&dom, cl);
318+
clnt_destroy(cl);
318319
if (list == NULL)
319-
return NULL;
320+
goto finally;
320321
if (list->stat != NIS_TRUE)
321-
return NULL;
322+
goto finally;
323+
324+
PyMem_DEL(server);
322325
return list->maps;
326+
327+
finally:
328+
PyMem_DEL(server);
329+
return NULL;
323330
}
324331

325332
static PyObject *
@@ -337,12 +344,14 @@ nis_maps (self, args)
337344
if ((list = PyList_New(0)) == NULL)
338345
return NULL;
339346
for (maps = maps->next; maps; maps = maps->next) {
340-
if (PyList_Append (list, PyString_FromString (maps->map)) < 0)
347+
PyObject *str = PyString_FromString(maps->map);
348+
if (!str || PyList_Append(list, str) < 0)
341349
{
342350
Py_DECREF(list);
343351
list = NULL;
344352
break;
345353
}
354+
Py_DECREF(str);
346355
}
347356
/* XXX Shouldn't we free the list of maps now? */
348357
return list;

Modules/pwdmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pwd_getpwall(self, args)
109109
Py_DECREF(d);
110110
return NULL;
111111
}
112+
Py_DECREF(v);
112113
}
113114
return d;
114115
}

Modules/regexmodule.c

Lines changed: 6 additions & 1 deletion

0 commit comments

Comments
 (0)