nikademus79 / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

free(0) #219

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
first lines of _psutil_osx.c:

static PyObject*
get_pid_list(PyObject* self, PyObject* args)
{
    kinfo_proc *proclist = NULL;
    kinfo_proc *orig_address = NULL;
    size_t num_processes;
    size_t idx;
    PyObject *pid;
    PyObject *retlist = PyList_New(0);

    if (get_proc_list(&proclist, &num_processes) != 0) {
        Py_DECREF(retlist);
        PyErr_SetString(PyExc_RuntimeError, "failed to retrieve process list.");
        return NULL;
    }

    if (num_processes > 0) {
        // save the address of proclist so we can free it later
        orig_address = proclist;
        for (idx=0; idx < num_processes; idx++) {
            pid = Py_BuildValue("i", proclist->kp_proc.p_pid);
            PyList_Append(retlist, pid);
            Py_XDECREF(pid);
            proclist++;
        }
    }
    free(orig_address);
    return retlist;
}

if num_processes <= 0, then orig_address is NULL, in which case, free(NULL) 
gets called.

Original issue reported on code.google.com by Jason.Donenfeld on 10 Oct 2011 at 3:22

GoogleCodeExporter commented 8 years ago
This is now fixed in r1156.
Thanks.

Original comment by g.rodola on 13 Oct 2011 at 9:55

GoogleCodeExporter commented 8 years ago
Note that free(NULL) has absolutely no effect anyway...

Original comment by wj32...@gmail.com on 14 Oct 2011 at 8:58

GoogleCodeExporter commented 8 years ago

Original comment by g.rodola on 21 Oct 2011 at 11:44

GoogleCodeExporter commented 8 years ago

Original comment by g.rodola on 21 Oct 2011 at 11:45

GoogleCodeExporter commented 8 years ago

Original comment by g.rodola on 29 Oct 2011 at 3:44

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Updated csets after the SVN -> Mercurial migration:
r1156 == revision b6f48bf442b6

Original comment by g.rodola on 2 Mar 2013 at 12:04