diff options
author | Sergey Mironov <grrwlf@gmail.com> | 2014-08-24 11:56:41 +0400 |
---|---|---|
committer | Sergey Mironov <grrwlf@gmail.com> | 2014-08-24 11:56:41 +0400 |
commit | 1bbc50639256f0a04b1866ad23a3945c17130068 (patch) | |
tree | 3dac67787e479ae96182e162e79651c72e4bbc70 | |
parent | a894904947777bbc797a69b1d55ca4008375acaf (diff) |
Check realloc's return code to prevent segfault on out of memory condition (Part 2)
-rw-r--r-- | src/c/request.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/c/request.c b/src/c/request.c index 9dc6aa59..d621aea7 100644 --- a/src/c/request.c +++ b/src/c/request.c @@ -444,11 +444,12 @@ request_result uw_request(uw_request_context rc, uw_context ctx, 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 @@ request_result uw_request(uw_request_context rc, uw_context ctx, 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); |