fixed various memory leaks/overruns/etc

I found many issues using AddressSanitizer and LeakSanitizer.
diff --git a/bbb_cape/src/bbb/cows_test.cc b/bbb_cape/src/bbb/cows_test.cc
index 06eba5b..e75af6b 100644
--- a/bbb_cape/src/bbb/cows_test.cc
+++ b/bbb_cape/src/bbb/cows_test.cc
@@ -7,8 +7,8 @@
 TEST(CowsTest, StupidZeros) {
   static const uint8_t kTestInput[] = {0x02, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01,
                                        0x00};
-  uint32_t input[3];
-  memcpy(input, kTestInput, 12);
+  uint32_t input[2];
+  memcpy(input, kTestInput, 8);
   uint32_t output[2];
   EXPECT_EQ(
       1u, cows_unstuff(input, sizeof(kTestInput), output, sizeof(output) * 4));