test: Fix memory leak in write_flash_vpnor

Running the test suite when configuring the source via `./bootstrap.sh dev`
leads to a failure of the write_flash_vpnor test with the report below in
test-suite.log. Add the necessary cleanup to ensure the test suite passes
cleanly.

===================================
   mboxd 2.1.0: ./test-suite.log
===================================

.. contents:: :depth: 2

FAIL: test/write_flash_vpnor
============================

[ 1519173867.854683139] Write flash @ 0x00003000 for 0x00000008 from 0x7ffe94d51ae0
[ 1519173867.854904248] Didn't find the file in the desired partition so copying[/tmp/prsv.RY6KiO/TEST3]
[ 1519173867.854979940] File copied from[/tmp/ro.dUeyxG/TEST3] to [/tmp/prsv.RY6KiO/TEST3]
[ 1519173867.855082198] Write flash @ 0x00001000 for 0x00000008 from 0x7ffe94d51ae0
[ 1519173867.857098822] Write flash @ 0x00002000 for 0x00000008 from 0x7ffe94d51ae0
[ 1519173867.857249802] Write flash @ 0x00002003 for 0x0000001c from 0x7ffe94d51ae0
[ 1519173867.857806832] Write flash @ 0x00002000 for 0x00000008 from 0x7ffe94d51ae0
[ 1519173867.857955823] Write flash @ 0x00002000 for 0x00000001 from 0x7ffe94d51ae0
[ 1519173867.858045089] Write flash @ 0x00002001 for 0x00000001 from 0x7ffe94d51ae1
[ 1519173867.858120016] Write flash @ 0x00002002 for 0x00000001 from 0x7ffe94d51ae2
[ 1519173867.858273459] Write flash @ 0x00002000 for 0x00000008 from 0x7ffe94d51b20
[ 1519173867.855134488] Can't open the RO partition for write[ 1519173867.857323229] Offset is beyond the partition file length[0x00000008]

=================================================================
==15139==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f98b42f6458 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0458)
    #1 0x56371c4cb52f in vpnor_create_partition_table_from_path /home/andrew/src/openbmc/phosphor-mboxd/mboxd_pnor_partition_table.cpp:40
    #2 0x56371c502013 in main test/write_flash_vpnor.cpp:145
    #3 0x7f98b225b1c0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x211c0)

Direct leak of 2 byte(s) in 1 object(s) allocated from:
    #0 0x7f98b42f4d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
    #1 0x56371c5003b6 in init(mbox_context*) test/write_flash_vpnor.cpp:115
    #2 0x56371c501c36 in main test/write_flash_vpnor.cpp:137
    #3 0x7f98b225b1c0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x211c0)

Indirect leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7f98b42f6458 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0458)
    #1 0x56371c3fa0c0 in __gnu_cxx::new_allocator<unsigned char>::allocate(unsigned long, void const*) (/home/andrew/src/openbmc/phosphor-mboxd/test/write_flash_vpnor+0x2850c0)
    #2 0x56371c3f3483 in std::allocator_traits<std::allocator<unsigned char> >::allocate(std::allocator<unsigned char>&, unsigned long) (/home/andrew/src/openbmc/phosphor-mboxd/test/write_flash_vpnor+0x27e483)
    #3 0x56371c3ebf6c in std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_allocate(unsigned long) (/home/andrew/src/openbmc/phosphor-mboxd/test/write_flash_vpnor+0x276f6c)
    #4 0x56371c3e3aa4 in std::vector<unsigned char, std::allocator<unsigned char> >::_M_default_append(unsigned long) (/home/andrew/src/openbmc/phosphor-mboxd/test/write_flash_vpnor+0x26eaa4)
    #5 0x56371c3d82c5 in std::vector<unsigned char, std::allocator<unsigned char> >::resize(unsigned long) (/home/andrew/src/openbmc/phosphor-mboxd/test/write_flash_vpnor+0x2632c5)
    #6 0x56371c3c623d in openpower::virtual_pnor::endianFixup(std::vector<unsigned char, std::allocator<unsigned char> > const&) /home/andrew/src/openbmc/phosphor-mboxd/pnor_partition_table.cpp:268
    #7 0x56371c3c2366 in openpower::virtual_pnor::partition::Table::Table(std::experimental::filesystem::v1::__cxx11::path&&, unsigned long, unsigned long) /home/andrew/src/openbmc/phosphor-mboxd/pnor_partition_table.cpp:38
    #8 0x56371c4cb844 in vpnor_create_partition_table_from_path /home/andrew/src/openbmc/phosphor-mboxd/mboxd_pnor_partition_table.cpp:45
    #9 0x56371c502013 in main test/write_flash_vpnor.cpp:145
    #10 0x7f98b225b1c0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x211c0)

Indirect leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7f98b42f6458 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0458)
    #1 0x56371c3fa0c0 in __gnu_cxx::new_allocator<unsigned char>::allocate(unsigned long, void const*) (/home/andrew/src/openbmc/phosphor-mboxd/test/write_flash_vpnor+0x2850c0)
    #2 0x56371c3f3483 in std::allocator_traits<std::allocator<unsigned char> >::allocate(std::allocator<unsigned char>&, unsigned long) (/home/andrew/src/openbmc/phosphor-mboxd/test/write_flash_vpnor+0x27e483)
    #3 0x56371c3ebf6c in std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_allocate(unsigned long) (/home/andrew/src/openbmc/phosphor-mboxd/test/write_flash_vpnor+0x276f6c)
    #4 0x56371c3e3aa4 in std::vector<unsigned char, std::allocator<unsigned char> >::_M_default_append(unsigned long) (/home/andrew/src/openbmc/phosphor-mboxd/test/write_flash_vpnor+0x26eaa4)
    #5 0x56371c3d82c5 in std::vector<unsigned char, std::allocator<unsigned char> >::resize(unsigned long) (/home/andrew/src/openbmc/phosphor-mboxd/test/write_flash_vpnor+0x2632c5)
    #6 0x56371c3d1b40 in openpower::virtual_pnor::partition::Table::allocateMemory(std::experimental::filesystem::v1::__cxx11::path const&) /home/andrew/src/openbmc/phosphor-mboxd/pnor_partition_table.cpp:78
    #7 0x56371c3c3006 in openpower::virtual_pnor::partition::Table::preparePartitions() /home/andrew/src/openbmc/phosphor-mboxd/pnor_partition_table.cpp:165
    #8 0x56371c3c2216 in openpower::virtual_pnor::partition::Table::Table(std::experimental::filesystem::v1::__cxx11::path&&, unsigned long, unsigned long) /home/andrew/src/openbmc/phosphor-mboxd/pnor_partition_table.cpp:36
    #9 0x56371c4cb844 in vpnor_create_partition_table_from_path /home/andrew/src/openbmc/phosphor-mboxd/mboxd_pnor_partition_table.cpp:45
    #10 0x56371c502013 in main test/write_flash_vpnor.cpp:145
    #11 0x7f98b225b1c0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x211c0)

Indirect leak of 432 byte(s) in 3 object(s) allocated from:
    #0 0x7f98b42f6458 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0458)
    #1 0x56371c5176b0 in void std::vector<std::experimental::filesystem::v1::__cxx11::path::_Cmpt, std::allocator<std::experimental::filesystem::v1::__cxx11::path::_Cmpt> >::_M_realloc_insert<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::experimental::filesystem::v1::__cxx11::path::_Type, unsigned long&>(__gnu_cxx::__normal_iterator<std::experimental::filesystem::v1::__cxx11::path::_Cmpt*, std::vector<std::experimental::filesystem::v1::__cxx11::path::_Cmpt, std::allocator<std::experimental::filesystem::v1::__cxx11::path::_Cmpt> > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::experimental::filesystem::v1::__cxx11::path::_Type&&, unsigned long&) (/home/andrew/src/openbmc/phosphor-mboxd/test/write_flash_vpnor+0x3a26b0)

Indirect leak of 144 byte(s) in 1 object(s) allocated from:
    #0 0x7f98b42f6458 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0458)
    #1 0x56371c4cb74b in vpnor_create_partition_table_from_path /home/andrew/src/openbmc/phosphor-mboxd/mboxd_pnor_partition_table.cpp:45
    #2 0x56371c502013 in main test/write_flash_vpnor.cpp:145
    #3 0x7f98b225b1c0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x211c0)

SUMMARY: AddressSanitizer: 8778 byte(s) leaked in 8 allocation(s).
FAIL test/write_flash_vpnor (exit status: 1)

Change-Id: I7d1a5262833146794e0298084e828e14821041b7
Fixes: openbmc/openbmc#2866
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/test/write_flash_vpnor.cpp b/test/write_flash_vpnor.cpp
index b9ba7ec..78b9ad8 100644
--- a/test/write_flash_vpnor.cpp
+++ b/test/write_flash_vpnor.cpp
@@ -263,5 +263,8 @@
     fs::remove_all(fs::path {tmpPRSVdir});
     fs::remove_all(fs::path {tmpPATCHdir});
 
+    destroy_vpnor(ctx);
+    free(ctx->flash_bmap);
+
     return rc;
 }