Author: janderwald Date: Mon Oct 8 00:17:54 2007 New Revision: 29445
URL: http://svn.reactos.org/svn/reactos?rev=29445&view=rev Log: - improve error checking - fix a memory leak
Modified: trunk/reactos/tools/sysreg/namedpipe_reader.cpp
Modified: trunk/reactos/tools/sysreg/namedpipe_reader.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/namedpipe_read... ============================================================================== --- trunk/reactos/tools/sysreg/namedpipe_reader.cpp (original) +++ trunk/reactos/tools/sysreg/namedpipe_reader.cpp Mon Oct 8 00:17:54 2007 @@ -70,10 +70,18 @@ else { cout << "NamedPipeReader::openPipe> successfully opened pipe" << endl; - m_BufferLength = 100; - m_Buffer = (char*)malloc(sizeof(char) * m_BufferLength); -#ifdef UNICODE - m_WBuffer = (WCHAR*)malloc(sizeof(WCHAR) * m_BufferLength); + + if (!m_Buffer) + { + m_BufferLength = 100; + m_Buffer = (char*)malloc(sizeof(char) * m_BufferLength); + } + +#ifdef UNICODE + if (!m_WBuffer) + { + m_WBuffer = (WCHAR*)malloc(sizeof(WCHAR) * m_BufferLength); + } #endif ConnectNamedPipe(h_Pipe, 0); @@ -90,8 +98,11 @@ else { cout << "NamedPipeReader::openPipe> successfully opened pipe handle: "<< h_Pipe << endl << "Src: " << PipeCmd << endl; - m_BufferLength = 100; - m_Buffer = (char*)malloc(sizeof(char) * m_BufferLength); + if (!m_Buffer) + { + m_BufferLength = 100; + m_Buffer = (char*)malloc(sizeof(char) * m_BufferLength); + } return true; } #endif @@ -240,12 +251,14 @@ if (!m_Buffer) { cerr << "Error: no memory" << endl; + return false; }
#ifdef UNICODE if (!m_WBuffer) { cerr << "Error: no memory" << endl; + return false; } #endif