repo: rxvt-unicode-sixel
action: commit
revision: 
path_from: 
revision_from: 7eef1af82613e71dd46a98d22b1c501af2bc5f73:
path_to: 
revision_to: 
git.thebackupbox.net
rxvt-unicode-sixel
git clone git://git.thebackupbox.net/rxvt-unicode-sixel
commit 7eef1af82613e71dd46a98d22b1c501af2bc5f73
Author: Emanuele Giaquinta 
Date:   Sat Aug 28 18:20:41 2010 +0000

    Slightly reorganize code to set icon image to avoid leaks on failure.

diff --git a/src/init.C b/src/init.C
index a7b0a8c46966223b9124fd8179c324cc790a62d7..
index ..a22d88c97b3fb6785ea8ee3cb3f91d5b907305e6 100644
--- a/src/init.C
+++ b/src/init.C
@@ -1385,34 +1385,34 @@ rxvt_term::create_windows (int argc, const char *const *argv)
         {
           int w = im->width;
           int h = im->height;
-          long *buffer = (long *)malloc ((2 + w * h) * sizeof (long));
           ASImage *result = scale_asimage (asv, im,
                                            w, h, ASA_ARGB32,
                                            100, ASIMAGE_QUALITY_DEFAULT);
           destroy_asimage (&im);

-          if (buffer && result)
+          if (result)
             {
-              ARGB32 *asbuf = result->alt.argb32;
-              buffer [0] = w;
-              buffer [1] = h;
+              long *buffer = (long *)malloc ((2 + w * h) * sizeof (long));
+              if (buffer)
+                {
+                  ARGB32 *asbuf = result->alt.argb32;
+                  buffer [0] = w;
+                  buffer [1] = h;

-              for (unsigned int i = 0; i < w * h; ++i)
-                buffer [i + 2] = asbuf [i];
+                  for (unsigned int i = 0; i < w * h; ++i)
+                    buffer [i + 2] = asbuf [i];

-              destroy_asimage (&result);
-              XChangeProperty (dpy, top, xa[XA_NET_WM_ICON], XA_CARDINAL, 32,
-                               PropModeReplace, (const unsigned char *) buffer, 2 + w * h);
-              free (buffer);
-            }
-          else
-            {
-              if (!buffer)
+                  XChangeProperty (dpy, top, xa[XA_NET_WM_ICON], XA_CARDINAL, 32,
+                                   PropModeReplace, (const unsigned char *) buffer, 2 + w * h);
+                  free (buffer);
+                }
+              else
                 rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n");

-              if (!result)
-                rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n");
+              destroy_asimage (&result);
             }
+          else
+            rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n");
         }
       else
         rxvt_warn ("Loading image icon failed, continuing without.\n");

-----END OF PAGE-----