Actually enforce the size in ChannelPreallocatedAllocator

We were ignoring the size when being asked to allocate.  Turns out
Flatbuffers rounds alignment up, so a 300 byte request becomes 304
bytes, corrupting the redzone.  Add a bunch of CHECKs here to catch it,
teach EventLoop to catch it, and catch it in the compiler.

Change-Id: I10488a2f96eeb7a955c6da436e6f9de1fcebbd14
diff --git a/aos/events/event_loop_param_test.cc b/aos/events/event_loop_param_test.cc
index 993011f..979de74 100644
--- a/aos/events/event_loop_param_test.cc
+++ b/aos/events/event_loop_param_test.cc
@@ -1158,6 +1158,35 @@
       "Channel pointer not found in configuration\\(\\)->channels\\(\\)");
 }
 
+// Verifies that the event loop implementations detect when Channel has an
+// invalid alignment.
+TEST_P(AbstractEventLoopDeathTest, InvalidChannelAlignment) {
+  const char *const kError = "multiple of alignment";
+  InvalidChannelAlignment();
+
+  auto loop = MakePrimary();
+
+  const Channel *channel = configuration::GetChannel(
+      loop->configuration(), "/test", "aos.TestMessage", "", nullptr);
+
+  EXPECT_DEATH({ loop->MakeRawSender(channel); }, kError);
+  EXPECT_DEATH({ loop->MakeSender<TestMessage>("/test"); }, kError);
+
+  EXPECT_DEATH({ loop->MakeRawFetcher(channel); }, kError);
+  EXPECT_DEATH({ loop->MakeFetcher<TestMessage>("/test"); }, kError);
+
+  EXPECT_DEATH(
+      { loop->MakeRawWatcher(channel, [](const Context &, const void *) {}); },
+      kError);
+  EXPECT_DEATH({ loop->MakeRawNoArgWatcher(channel, [](const Context &) {}); },
+               kError);
+
+  EXPECT_DEATH({ loop->MakeNoArgWatcher<TestMessage>("/test", []() {}); },
+               kError);
+  EXPECT_DEATH({ loop->MakeWatcher("/test", [](const TestMessage &) {}); },
+               kError);
+}
+
 // Verify that the send time on a message is roughly right when using a watcher.
 TEST_P(AbstractEventLoopTest, MessageSendTime) {
   auto loop1 = MakePrimary();