Commit 18bcc743 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Improve error handling.

parent 96957ef7
...@@ -483,7 +483,9 @@ main(int argc, char **argv) ...@@ -483,7 +483,9 @@ main(int argc, char **argv)
#endif #endif
init_signals(); init_signals();
resize_receive_buffer(1500); rc = resize_receive_buffer(1500);
if(rc < 0)
goto fail;
check_networks(); check_networks();
if(receive_buffer == NULL) if(receive_buffer == NULL)
goto fail; goto fail;
...@@ -826,17 +828,17 @@ schedule_neighbours_check(int msecs, int override) ...@@ -826,17 +828,17 @@ schedule_neighbours_check(int msecs, int override)
timeval_min(&check_neighbours_timeout, &timeout); timeval_min(&check_neighbours_timeout, &timeout);
} }
void int
resize_receive_buffer(int size) resize_receive_buffer(int size)
{ {
if(size <= receive_buffer_size) if(size <= receive_buffer_size)
return; return 0;
if(receive_buffer == NULL) { if(receive_buffer == NULL) {
receive_buffer = malloc(size); receive_buffer = malloc(size);
if(receive_buffer == NULL) { if(receive_buffer == NULL) {
perror("malloc(receive_buffer)"); perror("malloc(receive_buffer)");
return; return -1;
} }
receive_buffer_size = size; receive_buffer_size = size;
} else { } else {
...@@ -844,11 +846,12 @@ resize_receive_buffer(int size) ...@@ -844,11 +846,12 @@ resize_receive_buffer(int size)
new = realloc(receive_buffer, size); new = realloc(receive_buffer, size);
if(new == NULL) { if(new == NULL) {
perror("realloc(receive_buffer)"); perror("realloc(receive_buffer)");
return; return -1;
} }
receive_buffer = new; receive_buffer = new;
receive_buffer_size = size; receive_buffer_size = size;
} }
return 1;
} }
static void static void
......
...@@ -77,4 +77,4 @@ extern int max_request_hopcount; ...@@ -77,4 +77,4 @@ extern int max_request_hopcount;
extern int update_interval; extern int update_interval;
void schedule_neighbours_check(int msecs, int override); void schedule_neighbours_check(int msecs, int override);
void resize_receive_buffer(int size); int resize_receive_buffer(int size);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment