]> git.pld-linux.org Git - packages/xz.git/blob - xz-realloc.patch
- rel 2; realloc patch from git
[packages/xz.git] / xz-realloc.patch
1 From 3d93b6354927247a1569caf22ad27b07e97ee904 Mon Sep 17 00:00:00 2001
2 From: Lasse Collin <lasse.collin@tukaani.org>
3 Date: Fri, 28 Sep 2012 20:11:09 +0300
4 Subject: [PATCH] xz: Improve handling of failed realloc in xrealloc.
5
6 Thanks to Jim Meyering.
7 ---
8  src/xz/util.c |   14 ++++++++++++--
9  1 files changed, 12 insertions(+), 2 deletions(-)
10
11 diff --git a/src/xz/util.c b/src/xz/util.c
12 index 987b443..35850f4 100644
13 --- a/src/xz/util.c
14 +++ b/src/xz/util.c
15 @@ -26,9 +26,19 @@ xrealloc(void *ptr, size_t size)
16  {
17         assert(size > 0);
18  
19 +       // Save ptr so that we can free it if realloc fails.
20 +       // The point is that message_fatal ends up calling stdio functions
21 +       // which in some libc implementations might allocate memory from
22 +       // the heap. Freeing ptr improves the chances that there's free
23 +       // memory for stdio functions if they need it.
24 +       void *p = ptr;
25         ptr = realloc(ptr, size);
26 -       if (ptr == NULL)
27 -               message_fatal("%s", strerror(errno));
28 +
29 +       if (ptr == NULL) {
30 +               const int saved_errno = errno;
31 +               free(p);
32 +               message_fatal("%s", strerror(saved_errno));
33 +       }
34  
35         return ptr;
36  }
37 -- 
38 1.7.6
39
This page took 0.1935 seconds and 3 git commands to generate.