[Box Backup-commit] COMMIT r1514 - box/chris/general/lib/win32
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Sun, 15 Apr 2007 22:53:12 +0100
Author: chris
Date: 2007-04-15 22:53:12 +0100 (Sun, 15 Apr 2007)
New Revision: 1514
Modified:
box/chris/general/lib/win32/emu.cpp
Log:
Fix rare memory leak.
Fix emulated chdir to work with relative paths and with bbackupquery's
"sh" command (which doesn't like UNC paths).
Fix error messages by removing surplus newline kindly added by Windows.
Modified: box/chris/general/lib/win32/emu.cpp
===================================================================
--- box/chris/general/lib/win32/emu.cpp 2007-04-15 21:51:42 UTC (rev 1513)
+++ box/chris/general/lib/win32/emu.cpp 2007-04-15 21:53:12 UTC (rev 1514)
@@ -503,6 +503,10 @@
return std::string("failed to get error message");
}
+ // remove embedded newline
+ pMsgBuf[chars - 1] == 0;
+ pMsgBuf[chars - 2] == 0;
+
std::ostringstream line;
line << pMsgBuf << " (" << errorCode << ")";
LocalFree(pMsgBuf);
@@ -1474,6 +1478,7 @@
int emu_chdir(const char* pDirName)
{
+ /*
std::string AbsPathWithUnicode =
ConvertPathToAbsoluteUnicode(pDirName);
@@ -1484,11 +1489,19 @@
}
WCHAR* pBuffer = ConvertUtf8ToWideString(AbsPathWithUnicode.c_str());
+ */
+
+ WCHAR* pBuffer = ConvertUtf8ToWideString(pDirName);
if (!pBuffer) return -1;
+
int result = SetCurrentDirectoryW(pBuffer);
delete [] pBuffer;
+
if (result != 0) return 0;
+
errno = EACCES;
+ fprintf(stderr, "Failed to change directory to '%s': %s\n",
+ pDirName, GetErrorMessage(GetLastError()).c_str());
return -1;
}
@@ -1518,6 +1531,7 @@
if (result <= 0 || result >= len)
{
errno = EACCES;
+ delete [] pWide;
return NULL;
}