[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [obfsproxy/master] Log on OOM: don't just exit(1)
commit 731a24df11e79e1bd69350b5300027f6a17b44c2
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu Jul 14 11:51:25 2011 -0400
Log on OOM: don't just exit(1)
---
src/main.c | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/main.c b/src/main.c
index 10404c5..4a6c7d3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -152,6 +152,13 @@ handle_obfsproxy_args(const char **argv)
return i;
}
+static void
+die_oom(void)
+{
+ log_warn("Memory allocation failed: %s",strerror(errno));
+ exit(1);
+}
+
int
main(int argc, const char **argv)
{
@@ -201,7 +208,7 @@ main(int argc, const char **argv)
protocols = calloc(sizeof(int), (n_protocols+1));
if (!protocols)
- exit(1);
+ die_oom();
n_alloc = n_protocols+1;
/* Populate protocols and calculate n_protocols. */
@@ -215,7 +222,7 @@ main(int argc, const char **argv)
n_alloc *= 2;
realloc_temp = realloc(protocols, sizeof(int)*(n_alloc));
if (!realloc_temp)
- exit(1);
+ die_oom();
protocols = realloc_temp;
}
}
@@ -238,10 +245,10 @@ main(int argc, const char **argv)
*/
protocol_options = calloc(sizeof(char**), n_protocols);
if (!protocol_options)
- exit(1);
+ die_oom();
n_options_array = calloc(sizeof(int), n_protocols);
if (!n_options_array)
- exit(1);
+ die_oom();
/* Iterate through protocols. */
for (i=0;i<n_protocols;i++) {
@@ -271,7 +278,7 @@ main(int argc, const char **argv)
protocol_options[actual_protocols-1] =
calloc(sizeof(char*), (n_options));
if (!protocol_options[actual_protocols-1])
- exit(1);
+ die_oom();
/* Write the number of options to the correct place in n_options_array[]. */
n_options_array[actual_protocols-1] = n_options;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits