mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Cleanup and Error fixes
Add several frees that were missing to prevent memory leaks Replace strcpy with strdup where appropriate Replace _stat with __stat64 for building on Windows
This commit is contained in:
parent
97e178db3a
commit
b5f5b1a111
|
@ -56,10 +56,8 @@ char *get_user_config_dir(void)
|
||||||
)
|
)
|
||||||
if (!result) return NULL;
|
if (!result) return NULL;
|
||||||
|
|
||||||
user_config_dir = malloc(strlen(appdata) + 1);
|
user_config_dir = strdup(appdata);
|
||||||
if (user_config_dir) {
|
|
||||||
strcpy(user_config_dir, appdata);
|
|
||||||
}
|
|
||||||
return user_config_dir;
|
return user_config_dir;
|
||||||
|
|
||||||
#elif defined __APPLE__
|
#elif defined __APPLE__
|
||||||
|
@ -78,10 +76,7 @@ char *get_user_config_dir(void)
|
||||||
#else
|
#else
|
||||||
|
|
||||||
if (getenv("XDG_CONFIG_HOME")) {
|
if (getenv("XDG_CONFIG_HOME")) {
|
||||||
user_config_dir = malloc(strlen(getenv("XDG_CONFIG_HOME")) + 1);
|
user_config_dir = strdup(getenv("XDG_CONFIG_HOME"));
|
||||||
if (user_config_dir) {
|
|
||||||
strcpy(user_config_dir, getenv("XDG_CONFIG_HOME"));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
user_config_dir = malloc(strlen(getenv("HOME")) + strlen("/.config") + 1);
|
user_config_dir = malloc(strlen(getenv("HOME")) + strlen("/.config") + 1);
|
||||||
if (user_config_dir) {
|
if (user_config_dir) {
|
||||||
|
@ -109,12 +104,10 @@ int create_user_config_dir(char *path)
|
||||||
strcat(fullpath, CONFIGDIR);
|
strcat(fullpath, CONFIGDIR);
|
||||||
|
|
||||||
mkdir_err = _mkdir(fullpath);
|
mkdir_err = _mkdir(fullpath);
|
||||||
|
struct __stat64 buf;
|
||||||
if (mkdir_err) {
|
if (mkdir_err && (errno != EEXIST || _wstat64(fullpath, &buf) || !S_ISDIR(buf.st_mode))) {
|
||||||
if(errno != EEXIST) return -1;
|
free(fullpath);
|
||||||
struct _stat buf;
|
return -1;
|
||||||
if(_wstat64(fullpath, &buf)) return -1;
|
|
||||||
if(!S_ISDIR(buf.st_mode)) return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -122,10 +115,8 @@ int create_user_config_dir(char *path)
|
||||||
mkdir_err = mkdir(path, 0700);
|
mkdir_err = mkdir(path, 0700);
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
if(mkdir_err) {
|
if(mkdir_err && (errno != EEXIST || stat(path, &buf) || !S_ISDIR(buf.st_mode))) {
|
||||||
if(errno != EEXIST) return -1;
|
return -1;
|
||||||
if(stat(path, &buf)) return -1;
|
|
||||||
if(!S_ISDIR(buf.st_mode)) return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1);
|
char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1);
|
||||||
|
@ -134,10 +125,9 @@ int create_user_config_dir(char *path)
|
||||||
|
|
||||||
mkdir_err = mkdir(fullpath, 0700);
|
mkdir_err = mkdir(fullpath, 0700);
|
||||||
|
|
||||||
if(mkdir_err) {
|
if(mkdir_err && (errno != EEXIST || stat(fullpath, &buf) || !S_ISDIR(buf.st_mode))) {
|
||||||
if(errno != EEXIST) return -1;
|
free(fullpath);
|
||||||
if(stat(fullpath, &buf)) return -1;
|
return -1;
|
||||||
if(!S_ISDIR(buf.st_mode)) return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -370,6 +370,7 @@ int main(int argc, char *argv[])
|
||||||
init_term();
|
init_term();
|
||||||
init_tox();
|
init_tox();
|
||||||
load_data(filename);
|
load_data(filename);
|
||||||
|
free(filename);
|
||||||
init_windows();
|
init_windows();
|
||||||
init_window_status();
|
init_window_status();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user