Mercurial > repos > blastem
comparison paths.c @ 1858:dda7479f3bbb
Fix a couple of small memory leaks
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 29 Apr 2019 19:18:55 -0700 |
parents | ab3b465c052c |
children | bc68560b4a04 |
comparison
equal
deleted
inserted
replaced
1857:1844cf5a4045 | 1858:dda7479f3bbb |
---|---|
57 } | 57 } |
58 #endif | 58 #endif |
59 | 59 |
60 void get_initial_browse_path(char **dst) | 60 void get_initial_browse_path(char **dst) |
61 { | 61 { |
62 *dst = NULL; | 62 char *base = NULL; |
63 char *remember_path = tern_find_path(config, "ui\0remember_path\0", TVAL_PTR).ptrval; | 63 char *remember_path = tern_find_path(config, "ui\0remember_path\0", TVAL_PTR).ptrval; |
64 if (!remember_path || !strcmp("on", remember_path)) { | 64 if (!remember_path || !strcmp("on", remember_path)) { |
65 char *pathfname = alloc_concat(get_userdata_dir(), PATH_SEP "blastem" PATH_SEP "sticky_path"); | 65 char *pathfname = alloc_concat(get_userdata_dir(), PATH_SEP "blastem" PATH_SEP "sticky_path"); |
66 FILE *f = fopen(pathfname, "rb"); | 66 FILE *f = fopen(pathfname, "rb"); |
67 if (f) { | 67 if (f) { |
68 long pathsize = file_size(f); | 68 long pathsize = file_size(f); |
69 if (pathsize > 0) { | 69 if (pathsize > 0) { |
70 *dst = malloc(pathsize + 1); | 70 base = malloc(pathsize + 1); |
71 if (fread(*dst, 1, pathsize, f) != pathsize) { | 71 if (fread(base, 1, pathsize, f) != pathsize) { |
72 warning("Error restoring saved file browser path"); | 72 warning("Error restoring saved file browser path"); |
73 free(*dst); | 73 free(base); |
74 *dst = NULL; | 74 base = NULL; |
75 } else { | 75 } else { |
76 (*dst)[pathsize] = 0; | 76 base[pathsize] = 0; |
77 } | 77 } |
78 } | 78 } |
79 fclose(f); | 79 fclose(f); |
80 } | 80 } |
81 free(pathfname); | 81 free(pathfname); |
82 if (!current_path) { | 82 if (!current_path) { |
83 atexit(persist_path); | 83 atexit(persist_path); |
84 current_path = dst; | 84 current_path = dst; |
85 } | 85 } |
86 } | 86 } |
87 if (!*dst) { | 87 if (!base) { |
88 *dst = tern_find_path(config, "ui\0initial_path\0", TVAL_PTR).ptrval; | 88 base = tern_find_path(config, "ui\0initial_path\0", TVAL_PTR).ptrval; |
89 } | 89 } |
90 if (!*dst){ | 90 if (!base){ |
91 #ifdef __ANDROID__ | 91 #ifdef __ANDROID__ |
92 *dst = get_external_storage_path(); | 92 base = get_external_storage_path(); |
93 #else | 93 #else |
94 *dst = "$HOME"; | 94 base = "$HOME"; |
95 #endif | 95 #endif |
96 } | 96 } |
97 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); | 97 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); |
98 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); | 98 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); |
99 *dst = replace_vars(*dst, vars, 1); | 99 *dst = replace_vars(base, vars, 1); |
100 free(base); | |
100 tern_free(vars); | 101 tern_free(vars); |
101 } | 102 } |
102 | 103 |
103 char *path_append(const char *base, const char *suffix) | 104 char *path_append(const char *base, const char *suffix) |
104 { | 105 { |