From e077819626b31be31ca9eaef7962a186682c3691 Mon Sep 17 00:00:00 2001 From: bertliao Date: Fri, 23 Feb 2018 12:27:02 +0800 Subject: [PATCH] Fix 2 memory leak --- src/reqs.c | 6 +++++- src/transparent-proxy.c | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/reqs.c b/src/reqs.c index 0e4e5f7..01c2ed8 100644 --- a/src/reqs.c +++ b/src/reqs.c @@ -681,7 +681,11 @@ static int get_all_headers (int fd, hashmap_t hashofheaders) /* * Append the new line to the current header field. */ - tmp = (char *) saferealloc (header, len + linelen); + if( NULL == header ) { + tmp = (char *) safemalloc (len + linelen); + } else { + tmp = (char *) saferealloc (header, len + linelen); + } if (tmp == NULL) { safefree (header); safefree (line); diff --git a/src/transparent-proxy.c b/src/transparent-proxy.c index 5d0c8f6..3e3597c 100644 --- a/src/transparent-proxy.c +++ b/src/transparent-proxy.c @@ -38,6 +38,7 @@ static int build_url (char **url, const char *host, int port, const char *path) { int len; + char *tmp; assert (url != NULL); assert (host != NULL); @@ -45,10 +46,13 @@ static int build_url (char **url, const char *host, int port, const char *path) assert (path != NULL); len = strlen (host) + strlen (path) + 14; - *url = (char *) safemalloc (len); - if (*url == NULL) + + tmp = (char *) saferealloc (*url, len); + if (tmp == NULL) { return -1; - + } + *url = tmp; + return snprintf (*url, len, "http://%s:%d%s", host, port, path); }