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>
1 file changed
tree: d1a38a33d8ee91172f48d244fac9566796c39288
  1. Documentation/
  2. m4/
  3. test/
  4. xyz/
  5. .gitignore
  6. bootstrap.sh
  7. common.c
  8. common.h
  9. configure.ac
  10. dbus.h
  11. LICENSE
  12. Makefile.am
  13. mbox.h
  14. mboxctl.c
  15. mboxd.c
  16. mboxd_dbus.c
  17. mboxd_dbus.h
  18. mboxd_flash.h
  19. mboxd_flash_physical.c
  20. mboxd_flash_virtual.cpp
  21. mboxd_lpc.c
  22. mboxd_lpc.h
  23. mboxd_lpc_physical.c
  24. mboxd_lpc_virtual.cpp
  25. mboxd_msg.c
  26. mboxd_msg.h
  27. mboxd_pnor_partition_table.cpp
  28. mboxd_pnor_partition_table.h
  29. mboxd_windows.c
  30. mboxd_windows.h
  31. mtd.c
  32. pnor_partition.cpp
  33. pnor_partition.hpp
  34. pnor_partition_defs.h
  35. pnor_partition_table.cpp
  36. pnor_partition_table.hpp
  37. README.md
README.md

Copyright 2017 IBM

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

MBOX

This repo contains the protocol definition for the host to BMC mailbox communication specification which can be found in Documentation/mbox_procotol.md.

There is also a reference implementation of a BMC mailbox daemon, the details of which can be found in Documentation/mboxd.md.

Finally there is also an implementation of a mailbox daemon control program, the details of which can be found in Documentation/mboxctl.md.