summaryrefslogtreecommitdiffstats
path: root/base/gfx
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 22:03:00 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 22:03:00 +0000
commit104c81a649d539c0fc2e4c8bb08d8e1163179c53 (patch)
treef60c53fdb038a04783fb5c273afc8a2179857e5f /base/gfx
parentd841205ef77d7f98bf780516d3be96a3ba6c6f29 (diff)
downloadchromium_src-104c81a649d539c0fc2e4c8bb08d8e1163179c53.zip
chromium_src-104c81a649d539c0fc2e4c8bb08d8e1163179c53.tar.gz
chromium_src-104c81a649d539c0fc2e4c8bb08d8e1163179c53.tar.bz2
Fix a leak when we fail to load a gdkpixbuf. I meant to do this in
the last change, but forgot. Review URL: http://codereview.chromium.org/69042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14143 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/gfx')
-rwxr-xr-xbase/gfx/gtk_util.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/base/gfx/gtk_util.h b/base/gfx/gtk_util.h
index 110caf5..0d21216 100755
--- a/base/gfx/gtk_util.h
+++ b/base/gfx/gtk_util.h
@@ -8,6 +8,10 @@
#include <stdint.h>
#include <vector>
+#include <glib-object.h>
+
+#include "base/scoped_ptr.h"
+
typedef struct _GdkColor GdkColor;
typedef struct _GdkRegion GdkRegion;
@@ -30,4 +34,24 @@ void SubtractRectanglesFromRegion(GdkRegion* region,
} // namespace gfx
+namespace {
+// A helper class that will g_object_unref |p| when it goes out of scope.
+// This never adds a ref, it only unrefs.
+template <typename Type>
+struct GObjectUnrefer {
+ void operator()(Type* ptr) const {
+ if (ptr)
+ g_object_unref(ptr);
+ }
+};
+} // namespace
+
+// It's not legal C++ to have a templatized typedefs, so we wrap it in a
+// struct. When using this, you need to include ::Type. E.g.,
+// ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new());
+template<class T>
+struct ScopedGObject {
+ typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type;
+};
+
#endif // BASE_GFX_GTK_UTIL_H_