[Python-checkins] r46824 - in python/trunk/Modules/_ctypes: _ctypes.c callproc.c ctypes.h libffi/src/x86/darwin.S libffi_msvc/mingwin32.S stgdict.c

Neal Norwitz nnorwitz at gmail.com
Sat Jun 10 23:32:51 CEST 2006


2 issues, see below

On 6/10/06, thomas.heller <python-checkins at python.org> wrote:
> Author: thomas.heller
> Date: Sat Jun 10 21:51:46 2006
> New Revision: 46824
>
> Modified: python/trunk/Modules/_ctypes/callproc.c
> ==============================================================================
> --- python/trunk/Modules/_ctypes/callproc.c     (original)
> +++ python/trunk/Modules/_ctypes/callproc.c     Sat Jun 10 21:51:46 2006
> @@ -1444,7 +1444,64 @@
>  }
>  #endif
>
> +static PyObject *
> +resize(PyObject *self, PyObject *args)
> +{
...
> +       if (obj->b_size <= sizeof(obj->b_value)) {
> +               /* We are currently using the objects default buffer, but it
> +                  isn't large enough any more. */
> +               void *ptr = PyMem_Malloc(size);
> +               if (ptr == NULL)
> +                       return PyErr_NoMemory();
> +               memset(ptr, 0, size);
> +               memmove(ptr, obj->b_ptr, obj->b_size);
> +               obj->b_ptr = ptr;
> +               obj->b_size = size;
> +       } else {
> +               obj->b_ptr = PyMem_Realloc(obj->b_ptr, size);
> +               obj->b_size = size;
> +       }

Realloc can fail.  If it did this would leak memory.

> Modified: python/trunk/Modules/_ctypes/stgdict.c
> ==============================================================================
> --- python/trunk/Modules/_ctypes/stgdict.c      (original)
> +++ python/trunk/Modules/_ctypes/stgdict.c      Sat Jun 10 21:51:46 2006

> +static int
> +MakeFields(PyObject *type, CFieldObject *descr,
> +          Py_ssize_t index, Py_ssize_t offset)
> +{
...
> +               // Convert to PyArg_UnpackTuple...
> +               if (!PyArg_ParseTuple(pair, "OO", &fname, &ftype)) {
> +                       Py_DECREF(fieldlist);
> +                       return -1;
> +               }

Should use /* */ comments instead of //.


More information about the Python-checkins mailing list