# HG changeset patch # User Sergey Mironov # Date 1408867001 -14400 # Node ID b6adfe99bb087b37a47519f35e3b37c6e94acf28 # Parent 88841212f0bae33c215ecdbd9e19dc18869ca401 Check realloc's return code to prevent segfault on out of memory condition (Part 2) diff -r 88841212f0ba -r b6adfe99bb08 src/c/request.c --- 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);