]> git.sesse.net Git - cubemap/blobdiff - main.cpp
Do not segfault on unknown options.
[cubemap] / main.cpp
index be3e8ebcce8e81ca462c34937b3068cdc12e24b1..e953a8cea29d79da4579adb06a3580e989598a28 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -32,6 +32,7 @@ using namespace std;
 
 AccessLogThread *access_log = NULL;
 ServerPool *servers = NULL;
+vector<MarkPool *> mark_pools;
 volatile bool hupped = false;
 volatile bool stopped = false;
 
@@ -142,7 +143,6 @@ void create_streams(const Config &config,
                     const set<string> &deserialized_stream_ids,
                    map<string, Input *> *deserialized_inputs)
 {
-       vector<MarkPool *> mark_pools;  // FIXME: leak
        for (unsigned i = 0; i < config.mark_pools.size(); ++i) {
                const MarkPoolConfig &mp_config = config.mark_pools[i];
                mark_pools.push_back(new MarkPool(mp_config.from, mp_config.to));
@@ -248,9 +248,10 @@ int main(int argc, char **argv)
                static const option long_options[] = {
                        { "state", required_argument, 0, 's' },
                        { "test-config", no_argument, 0, 't' },
+                       { 0, 0, 0, 0 }
                };
                int option_index = 0;
-               int c = getopt_long (argc, argv, "s:t", long_options, &option_index);
+               int c = getopt_long(argc, argv, "s:t", long_options, &option_index);
      
                if (c == -1) {
                        break;
@@ -263,7 +264,8 @@ int main(int argc, char **argv)
                        test_config = true;
                        break;
                default:
-                       assert(false);
+                       fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
+                       exit(1);
                }
        }
 
@@ -406,6 +408,7 @@ start:
 
        if (stats_thread != NULL) {
                stats_thread->stop();
+               delete stats_thread;
        }
        for (size_t i = 0; i < acceptors.size(); ++i) {
                acceptors[i]->stop();
@@ -430,6 +433,12 @@ start:
                }
        }
        delete servers;
+
+       for (unsigned i = 0; i < mark_pools.size(); ++i) {
+               delete mark_pools[i];
+       }
+       mark_pools.clear();
+
        access_log->stop();
        delete access_log;
        shut_down_logging();