From 818d51068602b429b969ba02cfbcc1369cf1fa84 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 14 May 2012 22:32:07 +0200 Subject: [PATCH] Fix bugs reported by cpychecker MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Thanks to Dave Malcolm's cpychecker tool, this patch fixes a number of serious issues. All issues that were not deemed false-positives were fixed; some other issues in the same category that were found only by a high number of refcount checks are also fixed (I should split/simplify some parts of the code…). --- xattr.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/xattr.c b/xattr.c index 370324a..c4a5d6c 100644 --- a/xattr.c +++ b/xattr.c @@ -1,7 +1,7 @@ /* xattr - a python module for manipulating filesystem extended attributes - Copyright (C) 2002, 2003, 2006, 2008 Iustin Pop + Copyright (C) 2002, 2003, 2006, 2008, 2012 Iustin Pop This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -414,6 +414,11 @@ get_all(PyObject *self, PyObject *args, PyObject *keywds) /* Create the list which will hold the result */ mylist = PyList_New(0); + if(mylist == NULL) { + res = NULL; + goto free_buf_list; + } + nalloc = ESTIMATE_ATTR_SIZE; if((buf_val = PyMem_Malloc(nalloc)) == NULL) { Py_DECREF(mylist); @@ -450,6 +455,9 @@ get_all(PyObject *self, PyObject *args, PyObject *keywds) missing = 1; break; } + /* else we're dealing with a different error, which we + don't know how to handle nicely, so we abort */ + Py_DECREF(mylist); res = PyErr_SetFromErrno(PyExc_IOError); goto freebufval; } @@ -462,7 +470,11 @@ get_all(PyObject *self, PyObject *args, PyObject *keywds) #else my_tuple = Py_BuildValue("ss#", name, buf_val, nval); #endif - + if (my_tuple == NULL) { + Py_DECREF(mylist); + res = NULL; + goto freebufval; + } PyList_Append(mylist, my_tuple); Py_DECREF(my_tuple); } @@ -840,6 +852,8 @@ pylistxattr(PyObject *self, PyObject *args) /* Create the list which will hold the result */ mylist = PyList_New(nattrs); + if(mylist == NULL) + goto freebuf; /* Create and insert the attributes as strings in the list */ for(s = buf, nattrs = 0; s - buf < nret; s += strlen(s) + 1) { @@ -934,6 +948,8 @@ xattr_list(PyObject *self, PyObject *args, PyObject *keywds) } /* Create the list which will hold the result */ res = PyList_New(nattrs); + if(res == NULL) + goto freebuf; /* Create and insert the attributes as strings in the list */ for(s = buf, nattrs = 0; s - buf < nret; s += strlen(s) + 1) { -- 2.39.2