From 5d6f0ef296275f8c0dac513cfa6d49f71c2c5f61 Mon Sep 17 00:00:00 2001 From: Adelin Dobre Date: Mon, 7 Jan 2019 17:04:33 +0200 Subject: [PATCH] examples/c++/uart.cpp: Add fix for potential memory leak Signed-off-by: Adelin Dobre Signed-off-by: Mihai Tudor Panu --- examples/c++/uart.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/c++/uart.cpp b/examples/c++/uart.cpp index 81949ff..6ac6fa1 100644 --- a/examples/c++/uart.cpp +++ b/examples/c++/uart.cpp @@ -61,9 +61,10 @@ main(void) // If you have a valid platform configuration use numbers to represent uart // device. If not use raw mode where std::string is taken as a constructor // parameter - mraa::Uart* uart; + mraa::Uart* uart, *temp; try { uart = new mraa::Uart(UART_PORT); + temp = uart; } catch (std::exception& e) { std::cerr << e.what() << ", likely invalid platform config" << std::endl; } @@ -96,6 +97,7 @@ main(void) //! [Interesting] delete uart; + delete temp; return EXIT_SUCCESS; }