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
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static PyObject *mkgrent(p)
5151
Py_DECREF(w);
5252
return NULL;
5353
}
54+
Py_DECREF(x);
5455
}
5556
v = Py_BuildValue("(sslO)",
5657
p->gr_name,
@@ -112,6 +113,7 @@ static PyObject *grp_getgrall(self, args)
112113
Py_DECREF(d);
113114
return NULL;
114115
}
116+
Py_DECREF(v);
115117
}
116118
return d;
117119
}

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
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ symcomp(pattern, gdict)
518518
Py_XDECREF(npattern);
519519
return NULL;
520520
}
521+
Py_DECREF(group_name);
522+
Py_DECREF(group_index);
521523
++o; /* eat the '>' */
522524
break;
523525
}
@@ -573,6 +575,7 @@ regex_symcomp(self, args)
573575
PyObject *tran = NULL;
574576
PyObject *gdict = NULL;
575577
PyObject *npattern;
578+
PyObject *retval = NULL;
576579

577580
if (!PyArg_ParseTuple(args, "S|S", &pattern, &tran))
578581
return NULL;
@@ -583,7 +586,9 @@ regex_symcomp(self, args)
583586
Py_DECREF(pattern);
584587
return NULL;
585588
}
586-
return newregexobject(npattern, tran, pattern, gdict);
589+
retval = newregexobject(npattern, tran, pattern, gdict);
590+
Py_DECREF(npattern);
591+
return retval;
587592
}
588593

589594

0 commit comments

Comments
 (0)