Fix 2 memory leak

This commit is contained in:
bertliao 2018-02-23 12:27:02 +08:00
parent 9acb0cb16c
commit e077819626
2 changed files with 12 additions and 4 deletions

View File

@ -681,7 +681,11 @@ static int get_all_headers (int fd, hashmap_t hashofheaders)
/* /*
* Append the new line to the current header field. * 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) { if (tmp == NULL) {
safefree (header); safefree (header);
safefree (line); safefree (line);

View File

@ -38,6 +38,7 @@
static int build_url (char **url, const char *host, int port, const char *path) static int build_url (char **url, const char *host, int port, const char *path)
{ {
int len; int len;
char *tmp;
assert (url != NULL); assert (url != NULL);
assert (host != 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); assert (path != NULL);
len = strlen (host) + strlen (path) + 14; len = strlen (host) + strlen (path) + 14;
*url = (char *) safemalloc (len);
if (*url == NULL) tmp = (char *) saferealloc (*url, len);
if (tmp == NULL) {
return -1; return -1;
}
*url = tmp;
return snprintf (*url, len, "http://%s:%d%s", host, port, path); return snprintf (*url, len, "http://%s:%d%s", host, port, path);
} }