[pygame] fix #881545 - fix memory leak when saving png images
Jan Kaluža
jkaluza at fedoraproject.org
Tue Dec 4 07:04:46 UTC 2012
commit d3c17c423a3b7ffd29d569e09539f351fc3efe46
Author: Jan Kaluza <hanzz.k at gmail.com>
Date: Tue Dec 4 08:04:41 2012 +0100
fix #881545 - fix memory leak when saving png images
pygame-png-leak.patch | 44 ++++++++++++++++++++++++++++++++++++++++++++
pygame.spec | 7 ++++++-
2 files changed, 50 insertions(+), 1 deletions(-)
---
diff --git a/pygame-png-leak.patch b/pygame-png-leak.patch
new file mode 100644
index 0000000..a033ef8
--- /dev/null
+++ b/pygame-png-leak.patch
@@ -0,0 +1,44 @@
+diff --git a/src/imageext.c b/src/imageext.c
+index 80bce59..91c8edb 100644
+--- a/src/imageext.c
++++ b/src/imageext.c
+@@ -157,11 +157,15 @@ image_load_ext (PyObject* self, PyObject* arg)
+ #ifdef PNG_H
+
+ static int
+-write_png (char *file_name, png_bytep *rows, int w, int h, int colortype,
++write_png (const char *file_name,
++ png_bytep *rows,
++ int w,
++ int h,
++ int colortype,
+ int bitdepth)
+ {
+- png_structp png_ptr;
+- png_infop info_ptr;
++ png_structp png_ptr = NULL;
++ png_infop info_ptr = NULL;
+ FILE *fp = NULL;
+ char *doing = "open for writing";
+
+@@ -199,9 +203,20 @@ write_png (char *file_name, png_bytep *rows, int w, int h, int colortype,
+ doing = "closing file";
+ if(0 != fclose (fp))
+ goto fail;
++ png_destroy_write_struct(&png_ptr, &info_ptr);
+ return 0;
+
+ fail:
++ /*
++ * I don't see how to handle the case where png_ptr
++ * was allocated but info_ptr was not. However, those
++ * calls should only fail if memory is out and you are
++ * probably screwed regardless then. The resulting memory
++ * leak is the least of your concerns.
++ */
++ if( png_ptr && info_ptr ) {
++ png_destroy_write_struct(&png_ptr, &info_ptr);
++ }
+ SDL_SetError ("SavePNG: could not %s", doing);
+ return -1;
+ }
diff --git a/pygame.spec b/pygame.spec
index 16ec4ff..809d98c 100644
--- a/pygame.spec
+++ b/pygame.spec
@@ -2,7 +2,7 @@
Name: pygame
Version: 1.9.1
-Release: 10%{?dist}
+Release: 11%{?dist}
Summary: Python modules for writing games
Group: Development/Languages
@@ -16,6 +16,7 @@ Patch2: pygame-1.9.1-no-test-install.patch
# patch backported from upstream repository, V4L has been remove in linux-2.6.38
# http://svn.seul.org/viewcvs/viewvc.cgi?view=rev&root=PyGame&revision=3077
Patch3: pygame-remove-v4l.patch
+Patch4: pygame-png-leak.patch
Source0: http://pygame.org/ftp/%{name}-%{version}release.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@@ -52,6 +53,7 @@ pygame.
%patch1 -p1
%patch2 -p1
%patch3 -p1
+%patch4 -p1
# rpmlint fixes
find examples/ -type f -print0 | xargs -0 chmod -x
@@ -109,6 +111,9 @@ rm -rf $RPM_BUILD_ROOT
%changelog
+* Tue Dec 04 2012 Jan Kaluza <jkaluza at redhat.com> - 1.9.1-11
+- fix #881545 - fix memory leak when saving png images
+
* Mon Jul 30 2012 Jon Ciesla <limburgher at gmail.com> - 1.9.1-10
- Use system font, BZ 477444.
More information about the scm-commits
mailing list