]> granicus.if.org Git - python/commitdiff
Nailed a couple of memory leaks, caught by Purify.
authorBarry Warsaw <barry@python.org>
Thu, 9 Jan 1997 22:22:05 +0000 (22:22 +0000)
committerBarry Warsaw <barry@python.org>
Thu, 9 Jan 1997 22:22:05 +0000 (22:22 +0000)
Modules/grpmodule.c
Modules/nismodule.c
Modules/pwdmodule.c
Modules/regexmodule.c

index ccdba125246f5cbd4693ecb479256e612afbf14a..0199b6b033a448c5a51eb3eb2fcdd442f23071c3 100644 (file)
@@ -51,6 +51,7 @@ static PyObject *mkgrent(p)
                        Py_DECREF(w);
                        return NULL;
                }
+               Py_DECREF(x);
        }
        v = Py_BuildValue("(sslO)",
                       p->gr_name,
@@ -112,6 +113,7 @@ static PyObject *grp_getgrall(self, args)
                        Py_DECREF(d);
                        return NULL;
                }
+               Py_DECREF(v);
        }
        return d;
 }
index a00a0e6e1784b9fb36d7887d76be75244732a7da..586602699ae6d6e569f32b2e14ba81b421bd6814 100644 (file)
@@ -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;
index 69a81ef3543e5c0be3b25bf65be73fb231a0eeb2..4b09312e8a297b2c5cddd892b871ace321e4d176 100644 (file)
@@ -109,6 +109,7 @@ pwd_getpwall(self, args)
                        Py_DECREF(d);
                        return NULL;
                }
+               Py_DECREF(v);
        }
        return d;
 }
index 981a6e96980c90eee1006b2668bb88d62ae1dc26..695c2d24983063bdb588f0280a1f61b9003c852e 100644 (file)
@@ -518,6 +518,8 @@ symcomp(pattern, gdict)
                                            Py_XDECREF(npattern);
                                            return NULL;
                                    }
+                                   Py_DECREF(group_name);
+                                   Py_DECREF(group_index);
                                    ++o;     /* eat the '>' */
                                    break;
                                }
@@ -573,6 +575,7 @@ regex_symcomp(self, args)
        PyObject *tran = NULL;
        PyObject *gdict = NULL;
        PyObject *npattern;
+       PyObject *retval = NULL;
 
        if (!PyArg_ParseTuple(args, "S|S", &pattern, &tran))
                return NULL;
@@ -583,7 +586,9 @@ regex_symcomp(self, args)
                Py_DECREF(pattern);
                return NULL;
        }
-       return newregexobject(npattern, tran, pattern, gdict);
+       retval = newregexobject(npattern, tran, pattern, gdict);
+       Py_DECREF(npattern);
+       return retval;
 }