use xmalloc in x_get_window_property
authorBT Templeton <bpt@hcoop.net>
Thu, 28 Jun 2012 04:01:20 +0000 (00:01 -0400)
committerRobin Templeton <robin@terpri.org>
Mon, 9 Feb 2015 18:04:17 +0000 (13:04 -0500)
* src/alloc.c (x_get_window_property): Use `xmalloc'.

src/xselect.c

index 89ec1da..93de0f5 100644 (file)
@@ -1299,9 +1299,7 @@ x_get_window_property (Display *display, Window window, Atom property,
   if (total_size_max < bytes_remaining)
     goto size_overflow;
   total_size = bytes_remaining;
-  data = malloc (total_size + 1);
-  if (! data)
-    goto memory_exhausted;
+  data = xmalloc (total_size + 1);
 
   /* Now read, until we've gotten it all.  */
   while (bytes_remaining)
@@ -1347,15 +1345,11 @@ x_get_window_property (Display *display, Window window, Atom property,
 
       if (total_size - offset < bytes_gotten)
        {
-         unsigned char *data1;
          ptrdiff_t remaining_lim = total_size_max - offset - bytes_gotten;
          if (remaining_lim < 0 || remaining_lim < bytes_remaining)
            goto size_overflow;
          total_size = offset + bytes_gotten + bytes_remaining;
-         data1 = realloc (data, total_size + 1);
-         if (! data1)
-           goto memory_exhausted;
-         data = data1;
+         data = xrealloc (data, total_size + 1);
        }
 
       if (BITS_PER_LONG > 32 && *actual_format_ret == 32)
@@ -1386,14 +1380,9 @@ x_get_window_property (Display *display, Window window, Atom property,
   return;
 
  size_overflow:
-  free (data);
+  xfree (data);
   unblock_input ();
   memory_full (SIZE_MAX);
-
- memory_exhausted:
-  free (data);
-  unblock_input ();
-  memory_full (total_size + 1);
 }
 \f
 /* Use xfree, not XFree, to free the data obtained with this function.  */