---
 st.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/st.c b/st.c
index 1ff880a..aec58ce 100644
--- a/st.c
+++ b/st.c
@@ -261,19 +261,28 @@ xmalloc(size_t len)
 void *
 xrealloc(void *p, size_t len)
 {
-       if ((p = realloc(p, len)) == NULL)
+       void *tmp = realloc(p, len);
+
+       if (tmp == NULL) {
+               free(p);
                die("realloc: %s\n", strerror(errno));
+       }
 
+       p = tmp;
        return p;
 }
 
 char *
 xstrdup(char *s)
 {
-       if ((s = strdup(s)) == NULL)
+       char *tmp = strdup(s);
+
+       if (tmp == NULL) {
+               free(s);
                die("strdup: %s\n", strerror(errno));
+       }
 
-       return s;
+       return tmp;
 }
 
 size_t
-- 
2.20.1


Reply via email to