mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2024-11-23 20:38:07 +01:00
Ops, too many frees.
This commit is contained in:
parent
86d7806f27
commit
d1b901a491
1 changed files with 106 additions and 36 deletions
72
dll/wrap.cpp
72
dll/wrap.cpp
|
@ -97,7 +97,7 @@ bool match_path(char *path, int start, bool accept_same_case)
|
||||||
bool path_accessible = access(path, 0) == 0;
|
bool path_accessible = access(path, 0) == 0;
|
||||||
path[separator] = stored_char;
|
path[separator] = stored_char;
|
||||||
|
|
||||||
if (!path_accessible || !is_last_component && !match_path(path, separator, accept_same_case)) {
|
if (!path_accessible || (!is_last_component && !match_path(path, separator, accept_same_case))) {
|
||||||
DIR *current_directory = nullptr;
|
DIR *current_directory = nullptr;
|
||||||
int component = start + 1;
|
int component = start + 1;
|
||||||
|
|
||||||
|
@ -225,7 +225,9 @@ STEAMAPI_API FILE *__wrap_freopen(const char *path, const char *modes, FILE *str
|
||||||
bool is_writable = strpbrk(modes, "wa+") != 0;
|
bool is_writable = strpbrk(modes, "wa+") != 0;
|
||||||
const char *path_lowercased = lowercase_path(path, is_writable, true);
|
const char *path_lowercased = lowercase_path(path, is_writable, true);
|
||||||
FILE *result = freopen(path_lowercased, modes, stream);
|
FILE *result = freopen(path_lowercased, modes, stream);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +236,9 @@ STEAMAPI_API FILE *__wrap_fopen(const char *path, const char *modes)
|
||||||
bool is_writable = strpbrk(modes, "wa+") != 0;
|
bool is_writable = strpbrk(modes, "wa+") != 0;
|
||||||
const char *path_lowercased = lowercase_path(path, is_writable, true);
|
const char *path_lowercased = lowercase_path(path, is_writable, true);
|
||||||
FILE *result = fopen(path_lowercased, modes);
|
FILE *result = fopen(path_lowercased, modes);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +247,9 @@ STEAMAPI_API FILE *__wrap_fopen64(const char *path, const char *modes)
|
||||||
bool is_writable = strpbrk(modes, "wa+") != 0;
|
bool is_writable = strpbrk(modes, "wa+") != 0;
|
||||||
const char *path_lowercased = lowercase_path(path, is_writable, true);
|
const char *path_lowercased = lowercase_path(path, is_writable, true);
|
||||||
FILE *result = fopen64(path_lowercased, modes);
|
FILE *result = fopen64(path_lowercased, modes);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +258,9 @@ STEAMAPI_API int __wrap_open(const char *path, int flags, mode_t mode)
|
||||||
bool is_writable = flags & 3;
|
bool is_writable = flags & 3;
|
||||||
const char *path_lowercased = lowercase_path(path, is_writable, true);
|
const char *path_lowercased = lowercase_path(path, is_writable, true);
|
||||||
int result = open(path_lowercased, flags, mode);
|
int result = open(path_lowercased, flags, mode);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +269,9 @@ STEAMAPI_API int __wrap_open64(const char *path, int flags, mode_t mode)
|
||||||
bool is_writable = flags & 3;
|
bool is_writable = flags & 3;
|
||||||
const char *path_lowercased = lowercase_path(path, is_writable, true);
|
const char *path_lowercased = lowercase_path(path, is_writable, true);
|
||||||
int result = open64(path_lowercased, flags, mode);
|
int result = open64(path_lowercased, flags, mode);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +279,9 @@ STEAMAPI_API int __wrap_access(const char *path, int mode)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = access(path_lowercased, mode);
|
int result = access(path_lowercased, mode);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +289,9 @@ STEAMAPI_API int __wrap___xstat(int ver, const char * path, struct stat * stat_b
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = __xstat(ver, path_lowercased, stat_buf);
|
int result = __xstat(ver, path_lowercased, stat_buf);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +304,9 @@ STEAMAPI_API int __wrap___lxstat(int ver, const char * path, struct stat * stat_
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = __lxstat(ver, path_lowercased, stat_buf);
|
int result = __lxstat(ver, path_lowercased, stat_buf);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +319,9 @@ STEAMAPI_API int __wrap_scandir(const char *path, struct dirent ***namelist, int
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = scandir(path_lowercased, namelist, sel, compar);
|
int result = scandir(path_lowercased, namelist, sel, compar);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +329,9 @@ STEAMAPI_API int __wrap_scandir64(const char *path, struct dirent64 ***namelist,
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = scandir64(path_lowercased, namelist, sel, compar);
|
int result = scandir64(path_lowercased, namelist, sel, compar);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +339,9 @@ STEAMAPI_API DIR *__wrap_opendir(const char *path)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
DIR *result = opendir(path_lowercased);
|
DIR *result = opendir(path_lowercased);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,7 +349,9 @@ STEAMAPI_API int __wrap___xstat64(int ver, const char *path, struct stat64 *stat
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = __xstat64(ver, path_lowercased, stat_buf);
|
int result = __xstat64(ver, path_lowercased, stat_buf);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +359,9 @@ STEAMAPI_API int __wrap___lxstat64(int ver, const char *path, struct stat64 *sta
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = __lxstat64(ver, path_lowercased, stat_buf);
|
int result = __lxstat64(ver, path_lowercased, stat_buf);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +369,9 @@ STEAMAPI_API int __wrap_statvfs(const char *path, struct statvfs *buf)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = statvfs(path_lowercased, buf);
|
int result = statvfs(path_lowercased, buf);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +379,9 @@ STEAMAPI_API int __wrap_statvfs64(const char *path, struct statvfs64 *buf)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = statvfs64(path_lowercased, buf);
|
int result = statvfs64(path_lowercased, buf);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +389,9 @@ STEAMAPI_API int __wrap_chmod(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = chmod(path_lowercased, mode);
|
int result = chmod(path_lowercased, mode);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +399,9 @@ STEAMAPI_API int __wrap_chown(const char *path, uid_t owner, gid_t group)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = chown(path_lowercased, owner, group);
|
int result = chown(path_lowercased, owner, group);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +409,9 @@ STEAMAPI_API int __wrap_lchown(const char *path, uid_t owner, gid_t group)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = lchown(path_lowercased, owner, group);
|
int result = lchown(path_lowercased, owner, group);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,8 +420,12 @@ STEAMAPI_API int __wrap_symlink(const char *path1, const char *path2)
|
||||||
const char *path_lowercased1 = lowercase_path(path1, true, true);
|
const char *path_lowercased1 = lowercase_path(path1, true, true);
|
||||||
const char *path_lowercased2 = lowercase_path(path2, false, false);
|
const char *path_lowercased2 = lowercase_path(path2, false, false);
|
||||||
int result = symlink(path_lowercased1, path_lowercased2);
|
int result = symlink(path_lowercased1, path_lowercased2);
|
||||||
|
if (path_lowercased1 != path1) {
|
||||||
free((void *)path_lowercased1);
|
free((void *)path_lowercased1);
|
||||||
|
}
|
||||||
|
if (path_lowercased2 != path2) {
|
||||||
free((void *)path_lowercased2);
|
free((void *)path_lowercased2);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,8 +434,12 @@ STEAMAPI_API int __wrap_link(const char *path1, const char *path2)
|
||||||
const char *path_lowercased1 = lowercase_path(path1, true, true);
|
const char *path_lowercased1 = lowercase_path(path1, true, true);
|
||||||
const char *path_lowercased2 = lowercase_path(path2, false, false);
|
const char *path_lowercased2 = lowercase_path(path2, false, false);
|
||||||
int result = link(path_lowercased1, path_lowercased2);
|
int result = link(path_lowercased1, path_lowercased2);
|
||||||
|
if (path_lowercased1 != path1) {
|
||||||
free((void *)path_lowercased1);
|
free((void *)path_lowercased1);
|
||||||
|
}
|
||||||
|
if (path_lowercased2 != path2) {
|
||||||
free((void *)path_lowercased2);
|
free((void *)path_lowercased2);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +447,9 @@ STEAMAPI_API int __wrap_mknod(const char *path, mode_t mode, dev_t dev)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, true, true);
|
const char *path_lowercased = lowercase_path(path, true, true);
|
||||||
int result = __xmknod(1, path_lowercased, mode, &dev);
|
int result = __xmknod(1, path_lowercased, mode, &dev);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,8 +458,12 @@ STEAMAPI_API int __wrap_mount(const char *source, const char *target, const char
|
||||||
const char *source_lowercased = lowercase_path(source, false, false);
|
const char *source_lowercased = lowercase_path(source, false, false);
|
||||||
const char *target_lowercased = lowercase_path(target, false, false);
|
const char *target_lowercased = lowercase_path(target, false, false);
|
||||||
int result = mount(source_lowercased, target_lowercased, filesystemtype, mountflags, data);
|
int result = mount(source_lowercased, target_lowercased, filesystemtype, mountflags, data);
|
||||||
|
if (source_lowercased != source) {
|
||||||
free((void *)source_lowercased);
|
free((void *)source_lowercased);
|
||||||
|
}
|
||||||
|
if (target_lowercased != target) {
|
||||||
free((void *)target_lowercased);
|
free((void *)target_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +471,9 @@ STEAMAPI_API int __wrap_unlink(const char *path)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = unlink(path);
|
int result = unlink(path);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,7 +481,9 @@ STEAMAPI_API int __wrap_mkfifo(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, true, true);
|
const char *path_lowercased = lowercase_path(path, true, true);
|
||||||
int result = mkfifo(path, mode);
|
int result = mkfifo(path, mode);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,8 +492,12 @@ STEAMAPI_API int __wrap_rename(const char *old_name, const char *new_name)
|
||||||
const char *old_name_lowercased = lowercase_path(old_name, true, true);
|
const char *old_name_lowercased = lowercase_path(old_name, true, true);
|
||||||
const char *new_name_lowercased = lowercase_path(new_name, false, false);
|
const char *new_name_lowercased = lowercase_path(new_name, false, false);
|
||||||
int result = rename(old_name_lowercased, new_name_lowercased);
|
int result = rename(old_name_lowercased, new_name_lowercased);
|
||||||
|
if (old_name_lowercased != old_name) {
|
||||||
free((void *)old_name_lowercased);
|
free((void *)old_name_lowercased);
|
||||||
|
}
|
||||||
|
if (new_name_lowercased != new_name) {
|
||||||
free((void *)new_name_lowercased);
|
free((void *)new_name_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,7 +505,9 @@ STEAMAPI_API int __wrap_utime(const char *path, const struct utimbuf *times)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = utime(path_lowercased, times);
|
int result = utime(path_lowercased, times);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,7 +515,9 @@ STEAMAPI_API int __wrap_utimes(const char *path, const struct timeval times[2])
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = utimes(path_lowercased, times);
|
int result = utimes(path_lowercased, times);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,7 +525,9 @@ STEAMAPI_API int __wrap_mkdir(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, true, true);
|
const char *path_lowercased = lowercase_path(path, true, true);
|
||||||
int result = mkdir(path_lowercased, mode);
|
int result = mkdir(path_lowercased, mode);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,7 +535,9 @@ STEAMAPI_API int __wrap_rmdir(const char *path)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
int result = rmdir(path_lowercased);
|
int result = rmdir(path_lowercased);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,7 +545,9 @@ STEAMAPI_API void *__wrap_dlopen(const char *path, int mode)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
void * result = dlopen(path_lowercased, mode);
|
void * result = dlopen(path_lowercased, mode);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,7 +555,9 @@ STEAMAPI_API void *__wrap_dlmopen(Lmid_t lmid, const char *path, int flags)
|
||||||
{
|
{
|
||||||
const char *path_lowercased = lowercase_path(path, false, false);
|
const char *path_lowercased = lowercase_path(path, false, false);
|
||||||
void * result = dlmopen(lmid, path_lowercased, flags);
|
void * result = dlmopen(lmid, path_lowercased, flags);
|
||||||
|
if (path_lowercased != path) {
|
||||||
free((void *)path_lowercased);
|
free((void *)path_lowercased);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue