comparison src/c/request.c @ 2063:83bdb52962c9

Check realloc's return code to prevent segfault on out of memoty condition
author Sergey Mironov <grrwlf@gmail.com>
date Sat, 23 Aug 2014 11:59:34 +0000
parents 6add6d00ef5f
children b6adfe99bb08
comparison
equal deleted inserted replaced
2062:795b5b75453c 2063:83bdb52962c9
442 if (inputs) { 442 if (inputs) {
443 char *name, *value; 443 char *name, *value;
444 int len = strlen(inputs); 444 int len = strlen(inputs);
445 445
446 if (len+1 > rc->queryString_size) { 446 if (len+1 > rc->queryString_size) {
447 rc->queryString = realloc(rc->queryString, len+1);
448 if(rc->queryString == NULL) {
449 log_error(logger_data, "queryString is too long (not enough memory)\n");
450 return FAILED;
451 }
447 rc->queryString_size = len+1; 452 rc->queryString_size = len+1;
448 rc->queryString = realloc(rc->queryString, len+1);
449 } 453 }
450 strcpy(rc->queryString, inputs); 454 strcpy(rc->queryString, inputs);
451 455
452 while (*inputs) { 456 while (*inputs) {
453 name = inputs; 457 name = inputs;
478 size_t path_len = strlen(path); 482 size_t path_len = strlen(path);
479 483
480 on_success(ctx); 484 on_success(ctx);
481 485
482 if (path_len + 1 > rc->path_copy_size) { 486 if (path_len + 1 > rc->path_copy_size) {
487 rc->path_copy = realloc(rc->path_copy, path_len + 1);
488 if(rc->path_copy == NULL) {
489 log_error(logger_data, "Path is too long (not enough memory)\n");
490 return FAILED;
491 }
483 rc->path_copy_size = path_len + 1; 492 rc->path_copy_size = path_len + 1;
484 rc->path_copy = realloc(rc->path_copy, rc->path_copy_size);
485 } 493 }
486 strcpy(rc->path_copy, path); 494 strcpy(rc->path_copy, path);
487 495
488 uw_set_deadline(ctx, uw_time + uw_time_max); 496 uw_set_deadline(ctx, uw_time + uw_time_max);
489 fk = uw_begin(ctx, rc->path_copy); 497 fk = uw_begin(ctx, rc->path_copy);