|
ACE的日志输出宏ACE_HEX_DUMP存在内存泄露。解决方法是修改ACE_Log_Msg::log_hexdump函数,释放该函数中动态申请的内存buf
源代码如下:
int
ACE_Log_Msg::log_hexdump (ACE_Log_Priority log_priority,
const char *buffer,
size_t size,
const ACE_TCHAR *text)
{
// Only print the message if <priority_mask_> hasn't been reset to
// exclude this logging priority.
if (this->log_priority_enabled (log_priority) == 0)
return 0;
ACE_TCHAR* buf = 0;
const size_t buf_sz =
ACE_Log_Record::MAXLOGMSGLEN - ACE_Log_Record::VERBOSE_LEN - 58;
ACE_NEW_RETURN (buf, ACE_TCHAR[buf_sz], -1);
ACE_TCHAR *msg_buf = 0;
const size_t text_sz = text ? ACE_OS::strlen(text) : 0;
ACE_NEW_RETURN (msg_buf,
ACE_TCHAR[text_sz + 58],
-1);
buf[0] = 0; // in case size = 0
const size_t len = ACE::format_hexdump
(buffer, size, buf, buf_sz / sizeof (ACE_TCHAR) - text_sz);
int sz = 0;
if (text)
sz = ACE_OS::sprintf (msg_buf,
ACE_LIB_TEXT ("%s - "),
text);
sz += ACE_OS::sprintf (msg_buf + sz,
ACE_LIB_TEXT ("HEXDUMP ")
ACE_SIZE_T_FORMAT_SPECIFIER
ACE_LIB_TEXT (" bytes"),
size);
if (len < size)
ACE_OS::sprintf (msg_buf + sz,
ACE_LIB_TEXT (" (showing first ")
ACE_SIZE_T_FORMAT_SPECIFIER
ACE_LIB_TEXT (" bytes)"),
len);
// Now print out the formatted buffer.
this->log (log_priority,
ACE_LIB_TEXT ("%s\n%s"),
msg_buf,
buf);
delete [] msg_buf;
//add by Manfred.Fong
delete [] buf; //添加这行代码
return 0;
}
[ 本帖最后由 Manfred.Fong 于 2008-12-31 17:53 编辑 ] |
|