Mercurial > urweb
changeset 2068:b6adfe99bb08
Check realloc's return code to prevent segfault on out of memory condition (Part 2)
author | Sergey Mironov <grrwlf@gmail.com> |
---|---|
date | Sun, 24 Aug 2014 11:56:41 +0400 |
parents | 88841212f0ba |
children | 262dd74df39c |
files | src/c/request.c |
diffstat | 1 files changed, 6 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/c/request.c Thu Sep 04 08:40:14 2014 -0400 +++ b/src/c/request.c Sun Aug 24 11:56:41 2014 +0400 @@ -444,11 +444,12 @@ int len = strlen(inputs); if (len+1 > rc->queryString_size) { - rc->queryString = realloc(rc->queryString, len+1); - if(rc->queryString == NULL) { + char *qs = realloc(rc->queryString, len+1); + if(qs == NULL) { log_error(logger_data, "queryString is too long (not enough memory)\n"); return FAILED; } + rc->queryString = qs; rc->queryString_size = len+1; } strcpy(rc->queryString, inputs); @@ -484,11 +485,12 @@ on_success(ctx); if (path_len + 1 > rc->path_copy_size) { - rc->path_copy = realloc(rc->path_copy, path_len + 1); - if(rc->path_copy == NULL) { + char *pc = realloc(rc->path_copy, path_len + 1); + if(pc == NULL) { log_error(logger_data, "Path is too long (not enough memory)\n"); return FAILED; } + rc->path_copy = pc; rc->path_copy_size = path_len + 1; } strcpy(rc->path_copy, path);