Skip to content

Commit 7b67520

Browse files
committed
Updates
1 parent 24deda8 commit 7b67520

7 files changed

Lines changed: 63 additions & 69 deletions

File tree

formats/xml/rxml.c

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,15 @@ static void rxml_free_node(struct rxml_node *node)
6666

6767
for (attrib_node_head = node->attrib; attrib_node_head; )
6868
{
69-
struct rxml_attrib_node *next_attrib = NULL;
70-
71-
next_attrib = (struct rxml_attrib_node*)attrib_node_head->next;
72-
73-
if (next_attrib)
74-
{
75-
if (attrib_node_head->attrib)
76-
free(attrib_node_head->attrib);
77-
if (attrib_node_head->value)
78-
free(attrib_node_head->value);
79-
if (attrib_node_head)
80-
free(attrib_node_head);
81-
}
69+
struct rxml_attrib_node *next_attrib =
70+
(struct rxml_attrib_node*)attrib_node_head->next;
71+
72+
if (attrib_node_head->attrib)
73+
free(attrib_node_head->attrib);
74+
if (attrib_node_head->value)
75+
free(attrib_node_head->value);
76+
if (attrib_node_head)
77+
free(attrib_node_head);
8278

8379
attrib_node_head = next_attrib;
8480
}
@@ -161,6 +157,7 @@ rxml_document_t *rxml_load_document_string(const char *str)
161157

162158
case YXML_ELEMSTART:
163159
if (node) {
160+
164161
if (level > stack_i) {
165162
buf->stack[stack_i] = node;
166163
++stack_i;
@@ -177,7 +174,10 @@ rxml_document_t *rxml_load_document_string(const char *str)
177174
node = doc->root_node = (rxml_node_t*)calloc(1, sizeof(*node));
178175
}
179176

177+
if (node->name)
178+
free(node->name);
180179
node->name = strdup(x.elem);
180+
181181
attr = NULL;
182182

183183
++level;
@@ -188,7 +188,25 @@ rxml_document_t *rxml_load_document_string(const char *str)
188188

189189
if (valptr > buf->val) {
190190
*valptr = '\0';
191-
node->data = strdup(buf->val);
191+
192+
/* Original code was broken here:
193+
* > If an element ended on two successive
194+
* iterations, on the second iteration
195+
* the 'data' for the *previous* node would
196+
* get overwritten
197+
* > This effectively erased the data for the
198+
* previous node, *and* caused a memory leak
199+
* (due to the double strdup())
200+
* It seems the correct thing to do here is
201+
* only copy the data if the current 'level'
202+
* and 'stack index' are the same... */
203+
if (level == stack_i)
204+
{
205+
if (node->data)
206+
free(node->data);
207+
node->data = strdup(buf->val);
208+
}
209+
192210
valptr = buf->val;
193211
}
194212

@@ -211,7 +229,10 @@ rxml_document_t *rxml_load_document_string(const char *str)
211229
else
212230
attr = node->attrib = (struct rxml_attrib_node*)calloc(1, sizeof(*attr));
213231

232+
if (attr->attrib)
233+
free(attr->attrib);
214234
attr->attrib = strdup(x.attr);
235+
215236
valptr = buf->val;
216237
break;
217238

@@ -225,7 +246,11 @@ rxml_document_t *rxml_load_document_string(const char *str)
225246
case YXML_ATTREND:
226247
if (valptr > buf->val) {
227248
*valptr = '\0';
249+
250+
if (attr->value)
251+
free(attr->value);
228252
attr->value = strdup(buf->val);
253+
229254
valptr = buf->val;
230255
}
231256
break;

include/formats/rxml.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ struct rxml_node *rxml_root_node(rxml_document_t *doc);
6464

6565
const char *rxml_node_attrib(struct rxml_node *node, const char *attrib);
6666

67+
RETRO_END_DECLS
68+
6769
#endif

include/string/stdstring.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ char* string_tokenize(char **str, const char *delim);
133133
/* Removes every instance of character 'c' from 'str' */
134134
void string_remove_all_chars(char *str, char c);
135135

136+
/* Replaces every instance of character 'find' in 'str'
137+
* with character 'replace' */
138+
void string_replace_all_chars(char *str, char find, char replace);
139+
136140
/* Converts string to unsigned integer.
137141
* Returns 0 if string is invalid */
138142
unsigned string_to_unsigned(const char *str);

rthreads/rthreads.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ int sthread_detach(sthread_t *thread)
268268
free(thread);
269269
return 0;
270270
#else
271-
return pthread_detach(thread->id);
271+
int ret = pthread_detach(thread->id);
272+
free(thread);
273+
return ret;
272274
#endif
273275
}
274276

streams/chd_stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ chdstream_t *chdstream_open(const char *path, int32_t track)
246246
}
247247

248248
/* Only include pregap data if it was in the track file */
249-
if (!strcmp(meta.type, meta.pgtype))
249+
if (meta.pgtype[0] != 'V')
250250
pregap = meta.pregap;
251251
else
252252
pregap = 0;

string/stdstring.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,19 @@ void string_remove_all_chars(char *str, char c)
319319
*write_ptr = '\0';
320320
}
321321

322+
/* Replaces every instance of character 'find' in 'str'
323+
* with character 'replace' */
324+
void string_replace_all_chars(char *str, char find, char replace)
325+
{
326+
char *str_ptr = str;
327+
328+
if (string_is_empty(str))
329+
return;
330+
331+
while((str_ptr = strchr(str_ptr, find)) != NULL)
332+
*str_ptr++ = replace;
333+
}
334+
322335
/* Converts string to unsigned integer.
323336
* Returns 0 if string is invalid */
324337
unsigned string_to_unsigned(const char *str)

vfs/vfs_implementation_uwp.cpp

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -55,62 +55,10 @@ using namespace Windows::Storage::FileProperties;
5555
#include <string/stdstring.h>
5656
#include <retro_environment.h>
5757
#include <uwp/uwp_func.h>
58+
#include <uwp/uwp_async.h>
5859

5960
namespace
6061
{
61-
/* Dear Microsoft
62-
* I really appreciate all the effort you took to not provide any
63-
* synchronous file APIs and block all attempts to synchronously
64-
* wait for the results of async tasks for "smooth user experience",
65-
* but I'm not going to run and rewrite all RetroArch cores for
66-
* async I/O. I hope you like this hack I made instead.
67-
*/
68-
template<typename T>
69-
T RunAsync(std::function<concurrency::task<T>()> func)
70-
{
71-
volatile bool finished = false;
72-
Platform::Exception^ exception = nullptr;
73-
T result;
74-
75-
func().then([&finished, &exception, &result](concurrency::task<T> t) {
76-
try
77-
{
78-
result = t.get();
79-
}
80-
catch (Platform::Exception^ exception_)
81-
{
82-
exception = exception_;
83-
}
84-
finished = true;
85-
});
86-
87-
/* Don't stall the UI thread - prevents a deadlock */
88-
Windows::UI::Core::CoreWindow^ corewindow = Windows::UI::Core::CoreWindow::GetForCurrentThread();
89-
while (!finished)
90-
{
91-
if (corewindow) {
92-
corewindow->Dispatcher->ProcessEvents(Windows::UI::Core::CoreProcessEventsOption::ProcessAllIfPresent);
93-
}
94-
}
95-
96-
if (exception != nullptr)
97-
throw exception;
98-
return result;
99-
}
100-
101-
template<typename T>
102-
T RunAsyncAndCatchErrors(std::function<concurrency::task<T>()> func, T valueOnError)
103-
{
104-
try
105-
{
106-
return RunAsync<T>(func);
107-
}
108-
catch (Platform::Exception^ e)
109-
{
110-
return valueOnError;
111-
}
112-
}
113-
11462
void windowsize_path(wchar_t* path)
11563
{
11664
/* UWP deals with paths containing / instead of \ way worse than normal Windows */

0 commit comments

Comments
 (0)