ITS#7992 cleanup

check for utf8_to_utf16 failures
mdb.RE/0.9
Howard Chu 9 years ago
parent 18caeaa70b
commit ec32e90022
  1. 18
      libraries/liblmdb/mdb.c

@ -4470,7 +4470,9 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
#ifdef _WIN32 #ifdef _WIN32
wchar_t *wlpath; wchar_t *wlpath;
utf8_to_utf16(lpath, -1, &wlpath, NULL); rc = utf8_to_utf16(lpath, -1, &wlpath, NULL);
if (rc)
return rc;
env->me_lfd = CreateFileW(wlpath, GENERIC_READ|GENERIC_WRITE, env->me_lfd = CreateFileW(wlpath, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
@ -4758,7 +4760,9 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
len = OPEN_ALWAYS; len = OPEN_ALWAYS;
} }
mode = FILE_ATTRIBUTE_NORMAL; mode = FILE_ATTRIBUTE_NORMAL;
utf8_to_utf16(dpath, -1, &wpath, NULL); rc = utf8_to_utf16(dpath, -1, &wpath, NULL);
if (rc)
goto leave;
env->me_fd = CreateFileW(wpath, oflags, FILE_SHARE_READ|FILE_SHARE_WRITE, env->me_fd = CreateFileW(wpath, oflags, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, len, mode, NULL); NULL, len, mode, NULL);
free(wpath); free(wpath);
@ -4790,7 +4794,9 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
*/ */
#ifdef _WIN32 #ifdef _WIN32
len = OPEN_EXISTING; len = OPEN_EXISTING;
utf8_to_utf16(dpath, -1, &wpath, NULL); rc = utf8_to_utf16(dpath, -1, &wpath, NULL);
if (rc)
goto leave;
env->me_mfd = CreateFileW(wpath, oflags, env->me_mfd = CreateFileW(wpath, oflags,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, len, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, len,
mode | FILE_FLAG_WRITE_THROUGH, NULL); mode | FILE_FLAG_WRITE_THROUGH, NULL);
@ -9281,7 +9287,9 @@ mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags)
* already in the OS cache. * already in the OS cache.
*/ */
#ifdef _WIN32 #ifdef _WIN32
utf8_to_utf16(lpath, -1, &wpath, NULL); rc = utf8_to_utf16(lpath, -1, &wpath, NULL);
if (rc)
return rc;
newfd = CreateFileW(wpath, GENERIC_WRITE, 0, NULL, CREATE_NEW, newfd = CreateFileW(wpath, GENERIC_WRITE, 0, NULL, CREATE_NEW,
FILE_FLAG_NO_BUFFERING|FILE_FLAG_WRITE_THROUGH, NULL); FILE_FLAG_NO_BUFFERING|FILE_FLAG_WRITE_THROUGH, NULL);
free(wpath); free(wpath);
@ -10013,6 +10021,8 @@ static int utf8_to_utf16(const char *src, int srcsize, wchar_t **dst, int *dstsi
if (need == 0) if (need == 0)
return EINVAL; return EINVAL;
result = malloc(sizeof(wchar_t) * need); result = malloc(sizeof(wchar_t) * need);
if (!result)
return ENOMEM;
MultiByteToWideChar(CP_UTF8, 0, src, srcsize, result, need); MultiByteToWideChar(CP_UTF8, 0, src, srcsize, result, need);
if (dstsize) if (dstsize)
*dstsize = need; *dstsize = need;

Loading…
Cancel
Save