- pngObj = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
- if (!pngObj) goto cleanup;
-
- pngInfo = png_create_info_struct(pngObj);
- if (!pngInfo) goto cleanup;
-
- pngInfoEnd = png_create_info_struct(pngObj);
- if (!pngInfoEnd) goto cleanup;
+ struct png
+ {
+ png_structp context;
+ png_infop info;
+ png() :
+ context(png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0)),
+ info(png_create_info_struct(context))
+ {
+ if (!context || !info) throw 0;
+ }
+ ~png()
+ {
+ png_destroy_read_struct(context ? &context : 0,
+ info ? &info : 0, 0);
+ }
+ } png;