私のコードは、自分のコンピューターと他のテスト VM では正常に動作しますが、顧客のコンピューターでは動作が未定義です。_tmain の MessageBox で [OK] を押した後、コンパイルされた exe が CPU を 100% 使用し、爆発することがあります。
#include <windows.h>
#include <tchar.h>
#include <strsafe.h>
DWORD GetVS(TCHAR **sGetVS)
{
DWORD dwSize = 1024;
*sGetVS = (TCHAR *) calloc(dwSize,sizeof(TCHAR));
// Buffer for the environment variable value.
TCHAR *sBuffEnv = (TCHAR *) calloc(4096+1,sizeof(TCHAR));
DWORD dwRet = GetEnvironmentVariable(L"VS90COMNTOOLS", sBuffEnv, 4096);
if (dwRet)
{
StringCchCopy(*sGetVS,_tcslen(sBuffEnv)+1,sBuffEnv);
MessageBox(0,sBuffEnv,*sGetVS,0);
_tcslwr_s(*sGetVS,_tcslen(*sGetVS)+1); // +1 is required for the null char
}
free(sBuffEnv);sBuffEnv=NULL;
return 1;
}
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR *sTemp = NULL;
GetVS(&sTemp);
MessageBox(0,sTemp,L"",0);
free(sTemp);
return 0;
}
free
最後を削除しようとしましたが、 sTemp=NULL;
afterfree
を追加しましたが、同じ問題が発生しています。
ありがとう!