Page 1 of 1

[1.0.6-git] physfs_rwops memory leak

Posted: Thu Nov 28, 2013 1:15 pm
by johnnyzero
PhysFS's PHYSFS_close() function was changed to have the same error code style as fclose and many other standard C functions (return an error code, zero indicates no error). However, src/physfs/physfsrwops.c was never updated to reflect this change. The result? Every file opened by T-Engine never gets closed / garbage collected correctly.

Relevant commit: abe424d

Simple fix:

Code: Select all

diff --git a/src/physfs/physfsrwops.c b/src/physfs/physfsrwops.c
index a661c1a..a5a0bbd 100644
--- a/src/physfs/physfsrwops.c
+++ b/src/physfs/physfsrwops.c
@@ -126,7 +126,8 @@ static size_t physfsrwops_write(SDL_RWops *rw, const void *ptr, size_t size, siz
 static int physfsrwops_close(SDL_RWops *rw)
 {
     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
-    if (!PHYSFS_close(handle))
+    /* Note: PHYSFS_close was modified to return zero on success */
+    if (PHYSFS_close(handle))
     {
         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
         return(-1);

Re: [1.0.6-git] physfs_rwops memory leak

Posted: Fri Nov 29, 2013 11:46 am
by johnnyzero
Update: patch accepted into trunk.

Code: Select all

commit b163842339205b74d077ee83c2a7de152d40bb08
Author: DarkGod <darkgod@net-core.org>
Date:   Thu Nov 28 20:04:40 2013 +0100

    fix rwops close