Skip to content

Commit 78296a3

Browse files
committed
Proper refcounting and cleanup in transform.pixelate, update versionadded tag
1 parent cf64560 commit 78296a3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

buildconfig/stubs/pygame/transform.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,5 +480,5 @@ def pixelate(
480480
481481
:returns: A new surface that's been pixelated.
482482
483-
..versionadded:: 2.5.5
483+
..versionadded:: 2.5.6
484484
"""

src_c/transform.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4264,17 +4264,23 @@ surf_pixelate(PyObject *self, PyObject *args, PyObject *kwargs)
42644264
SDL_Surface *temp = scale_to(src, NULL, width, height);
42654265
intermediate = pgSurface_New(temp);
42664266
if (intermediate == NULL) {
4267+
SDL_FreeSurface(temp);
42674268
return NULL; /* Exception already set in scale_to */
42684269
}
42694270
new_surf = scale_to(intermediate, dst, src->surf->w, src->surf->h);
42704271
if (new_surf == NULL) {
4272+
Py_DECREF(intermediate);
42714273
return NULL; /* Exception already set in scale_to */
42724274
}
42734275

42744276
if (dst) {
42754277
Py_INCREF(dst);
4278+
Py_DECREF(intermediate);
42764279
return (PyObject *)dst;
42774280
}
4281+
4282+
Py_DECREF(intermediate);
4283+
42784284
return (PyObject *)pgSurface_New(new_surf);
42794285
}
42804286

0 commit comments

Comments
 (0)