Fix segfault in ~BPFModule on syntax error
authorBrenden Blanco <bblanco@plumgrid.com>
Fri, 5 Feb 2016 22:49:10 +0000 (14:49 -0800)
committerBrenden Blanco <bblanco@plumgrid.com>
Fri, 5 Feb 2016 22:54:43 +0000 (14:54 -0800)
~BPFModule was segfaulting because tables_ was an empty pointer. The
pointer is valid only for valid compilations. Add a test as well.

Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>
src/cc/bpf_module.cc
tests/cc/test_clang.py

index 6828909..7e1a409 100644 (file)
@@ -114,9 +114,11 @@ BPFModule::~BPFModule() {
   engine_.reset();
   rw_engine_.reset();
   ctx_.reset();
-  for (auto table : *tables_) {
-    if (table.is_shared)
-      SharedTables::instance()->remove_fd(table.name);
+  if (tables_) {
+    for (auto table : *tables_) {
+      if (table.is_shared)
+        SharedTables::instance()->remove_fd(table.name);
+    }
   }
 }
 
index 5811c22..87f2bd4 100755 (executable)
@@ -299,5 +299,9 @@ BPF_TABLE("array", int, union emptyu, t3, 1);
         b1 = BPF(text="""BPF_TABLE_PUBLIC("hash", int, int, table1, 10);""")
         b2 = BPF(text="""BPF_TABLE("extern", int, int, table1, 10);""")
 
+    def test_syntax_error(self):
+        with self.assertRaises(Exception):
+            b = BPF(text="""int failure(void *ctx) { if (); return 0; }""")
+
 if __name__ == "__main__":
     main()