Commits

Lenard Lindstrom committed 6edd090

Fix some CPyChecker detected bugs in imageext.c and font.c

- image_save_ext: memory leak on variable oencoded
- fontmodule_init: unhandled Python exception
- font_render: possible use of undefined variable rgba. This was a false
positive, as variable rgba is set by RGBAFromColorObj. However, using an
initializer is a safe practice, and removes the warning.

Comments (0)

Files changed (2)

     int istrue;
 
     result = font_autoinit (self);
+    if (result == NULL)
+        return NULL;
     istrue = PyObject_IsTrue (result);
     Py_DECREF (result);
     if (!istrue)
     int aa;
     PyObject* text, *final;
     PyObject* fg_rgba_obj, *bg_rgba_obj = NULL;
-    Uint8 rgba[4];
+    Uint8 rgba[] = {0, 0, 0, 0};
     SDL_Surface* surf;
     SDL_Color foreg, backg;
     int just_return;
     foreg.r = rgba[0];
     foreg.g = rgba[1];
     foreg.b = rgba[2];
+    foreg.unused = 0;
     if (bg_rgba_obj != NULL) {
         if (!RGBAFromColorObj(bg_rgba_obj, rgba)) {
             bg_rgba_obj = NULL;
 {
     PyObject *surfobj;
     PyObject *obj;
-    PyObject *oencoded;
+    PyObject *oencoded = NULL;
     SDL_Surface *surf;
     SDL_Surface *temp = NULL;
     int result = 1;
     if (!PyArg_ParseTuple(arg, "O!O", &PySurface_Type, &surfobj, &obj)) {
         return NULL;
     }
-    surf = PySurface_AsSurface(surfobj);
 
     surf = PySurface_AsSurface(surfobj);
     if (surf->flags & SDL_OPENGL) {
         PySurface_Unprep(surfobj);
     }
 
+    Py_XDECREF(oencoded);
     if (result == -2) {
         /* Python error raised elsewhere */
         return NULL;