[1.0.6-git] physfs_rwops memory leak

Moderator: Moderator

Post Reply
Message
Author
johnnyzero
Thalore
Posts: 148
Joined: Tue Feb 28, 2012 6:36 am

[1.0.6-git] physfs_rwops memory leak

#1 Post 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);

johnnyzero
Thalore
Posts: 148
Joined: Tue Feb 28, 2012 6:36 am

Re: [1.0.6-git] physfs_rwops memory leak

#2 Post 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

Post Reply