jackba / wy-internal-system

Automatically exported from code.google.com/p/wy-internal-system
0 stars 0 forks source link

Memory Leakage Auditor #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Memory Leakage Auditor

Original issue reported on code.google.com by Giggs...@gmail.com on 23 Feb 2012 at 6:59

GoogleCodeExporter commented 9 years ago

    UPLOG(m_srv_gm_update_meta,("fail to push receive entry"))

#define UPLOG(premsg,text)       \
    UPLOG_print(UPLOG_LEVEL_NORMAL,premsg, text)

#define UPLOG_print(level,premsg,text)                          \
    {                                                           \
        if(level >= UPLOG_LEVEL_CURRENT)                        \
        {                                                       \
            uplog_printout(__FILE__,__LINE__,#premsg);          \
            uplog_printtext text;                               \
        }                                                       \
    }

void uplog_printout(char* filename, int line, char* func)
{
    int     i;
    int     length          = strlen(filename);
    char*   newFileName     = NULL;
#ifdef UP_LOG_THREAD_SAFE
    if(m_uclog_mutex != UP_NULL)
    {
        up_mutex_lock(m_uclog_mutex);
    }
#endif
    memset(m_log_buffer, 0, UP_LOG_BUFFER_SIZE);

    // Clean up the directory part in the fullpath of source file //
    for ( i = length - 1 ; i >= 0 ; i-- )
    {
        if ( filename[i] == '\\' || filename[i] == '/' ) break;
    }
    newFileName = i < (length - 1) ?
                    ((char *) (filename + i + 1)) :
                    (char *) filename;

    sprintf(m_log_buffer, "[%15s#%4d][%18s]\n", newFileName,line,func);

    if(UP_ENABLE_LOG_FILE)
    {
        uplog_openLogfile();
        if(m_log_fileHandle != (UpFileHandle)UP_INVALID_INDEX && up_fs_tell(m_log_fileHandle, 0) < UP_LOG_FILE_MAX_SIZE)
        {
            up_fs_write(m_log_fileHandle, (void*)m_log_buffer, strlen(m_log_buffer), 0);
        }
        uplog_closeLogfile();
    }
    else
    {
//      printf("%s",m_log_buffer);
        OutputDebugStringA(m_log_buffer);
    }

#ifdef UP_LOG_THREAD_SAFE
    if(m_uclog_mutex != UP_NULL)
    {
        up_mutex_unlock(m_uclog_mutex);
    }
#endif
}

void uplog_printtext(char* text,...)
{
    va_list     ap;
#ifdef UP_LOG_THREAD_SAFE
    if(m_uclog_mutex != UP_NULL)
    {
        up_mutex_lock(m_uclog_mutex);
    }
#endif

    if(text == UP_NULL) text = "(up_log_warning) the text is NULL";

    if(strlen((const char*)text) >= UP_LOG_BUFFER_SIZE)
    {
        m_log_buffer[0] = '\0';
        strcpy(m_log_buffer, "warning!!! print buffer size is only 8 KB");
    }
    else
    {
        va_start(ap, text);

        vsprintf(m_log_buffer, text, ap);

        va_end(ap);
    }

    if(UP_ENABLE_LOG_FILE)
    {
        uplog_openLogfile();
        if(m_log_fileHandle != (UpFileHandle)UP_INVALID_INDEX && up_fs_tell(m_log_fileHandle, 0) < UP_LOG_FILE_MAX_SIZE)
        {
            up_fs_write(m_log_fileHandle, (void*)m_log_buffer, strlen(m_log_buffer), 0);
            up_fs_write(m_log_fileHandle,"\n", 1,  0);
        }
        uplog_closeLogfile();
    }
    else
    {
//      printf("%s\n",m_log_buffer);
        OutputDebugStringA(m_log_buffer);
    }

#ifdef UP_LOG_THREAD_SAFE
    if(m_uclog_mutex != UP_NULL)
    {
        up_mutex_unlock(m_uclog_mutex);
    }
#endif

    memset((void*)m_log_buffer, 0, UP_LOG_BUFFER_SIZE);
}

Original comment by Giggs...@gmail.com on 24 Feb 2012 at 12:58

GoogleCodeExporter commented 9 years ago
char *WideCharToChar(wchar_t *pwszWideChar)
{
    if (!pwszWideChar)
    {
        return NULL;
    }

//  size_t iOriginalSize = wcslen(pwszWideChar) + 1;
    size_t iOriginalSize = WideCharToMultiByte(CP_OEMCP, NULL, pwszWideChar, -1, NULL, 0, NULL, FALSE);
    size_t iConvertedSize = 0; 
    char *pszChar = NULL;
    pszChar = new char[iOriginalSize];
    memset(pszChar, 0, iOriginalSize);
    if (!pszChar)
    {
        return NULL;
    }
//  wcstombs_s(&iConvertedSize, pszChar, iOriginalSize, pwszWideChar , 
_TRUNCATE);
    WideCharToMultiByte (CP_OEMCP, NULL, pwszWideChar, -1, pszChar, iOriginalSize, NULL, FALSE);

    return pszChar;
}

wchar_t *CharToWideChar(char *pszChar)
{
    if (!pszChar)
    {
        return NULL;
    }
    wchar_t* wszWideChar = NULL;  
    unsigned int dwLen = MultiByteToWideChar(CP_ACP, 0, pszChar, -1, NULL, 0);  
    wszWideChar = NULL;
    wszWideChar = new wchar_t[dwLen];  
    if (!wszWideChar)
    {
        return NULL;
    }
    MultiByteToWideChar(CP_ACP, 0, pszChar, -1, wszWideChar, dwLen);  
    return wszWideChar;
}

    wchar_t a[3]=L"中国";
    char *p = "r中国";
    int i = strlen(p);//79
    int i2 = i;
    wchar_t *pw = CharToWideChar(p);
    i = wcslen(pw);//61
    i2 = i;
    char *p2 = WideCharToChar(pw);
    wchar_t *w = pw;
    char *p3 = p2;
    i = strlen(p2);
    i2 = i;

    wchar_t *pw2 = L"i误差";
    i = wcslen(pw2);//58
    i2 = i;
    char *pp = WideCharToChar(pw2);
    char *pp2 = pp;
    i = strlen(pp);//74
    i2 = i;
    wchar_t *pwww = CharToWideChar(pp2);
    wchar_t *pww2 = pwww;
    i = wcslen(pwww);//58
    i2 = i;

    return 0;

Original comment by Giggs...@gmail.com on 15 May 2013 at 8:43

GoogleCodeExporter commented 9 years ago
win7与Ubuntu 12.04双系统修改启动项顺序 .
sudo mv /etc/grub.d/30_os-prober /etc/grub.d/08_os-prober
sudo update-grub(这个命令会重新生成/boot/grub/grub.cfg)

Original comment by Giggs...@gmail.com on 15 May 2013 at 8:46