]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[Backport r51232 | neal.norwitz]
authorAndrew M. Kuchling <amk@amk.ca>
Wed, 4 Oct 2006 13:20:05 +0000 (13:20 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Wed, 4 Oct 2006 13:20:05 +0000 (13:20 +0000)
Verify verdat which is returned from malloc is not NULL.
Ensure we don't pass NULL to free.

Klocwork #306 (at least the first part, checking malloc)

Modules/rgbimgmodule.c

index 8c70d95e74ff8d82ab3590652369a05f6618646f..c5190c2d2166641eb490bc425f5bb4cadf94e57e 100644 (file)
@@ -410,6 +410,11 @@ longimagedata(PyObject *self, PyObject *args)
                addlongimgtag(base, xsize, ysize);
 #endif
                verdat = (unsigned char *)malloc(xsize);
+               if (!verdat) {
+                       Py_CLEAR(rv);
+                       goto finally;
+               }
+
                fseek(inf, 512, SEEK_SET);
                for (z = 0; z < zsize; z++) {
                        lptr = base;
@@ -431,10 +436,14 @@ longimagedata(PyObject *self, PyObject *args)
                        copybw((Py_Int32 *) base, xsize * ysize);
        }
   finally:
-       free(starttab);
-       free(lengthtab);
-       free(rledat);
-       free(verdat);
+       if (starttab)
+               free(starttab);
+       if (lengthtab)
+               free(lengthtab);
+       if (rledat)
+               free(rledat);
+       if (verdat)
+               free(verdat);
        fclose(inf);
        return rv;
 }