From 62fb097a9b619d9a62b9316ff289cc57265053f1 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 23 Feb 2017 16:53:28 +0100 Subject: [PATCH] [fix] free state file --- lib/mfrc522/source/loop.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/mfrc522/source/loop.php b/lib/mfrc522/source/loop.php index 9f94774..7f54a53 100755 --- a/lib/mfrc522/source/loop.php +++ b/lib/mfrc522/source/loop.php @@ -5,7 +5,6 @@ require_once __DIR__.'/../../include/php/const'; $f_auth; - $f_gstate; $f_accesslog; $f_actions; @@ -26,8 +25,8 @@ */ function get_gstate(){ - /* (1) Export global file descriptor */ - global $f_gstate; + /* (1) Initialize file descriptor */ + $f_gstate = new SplFileObject(STATE_CONF, 'r'); /* (2) Read first line */ $f_gstate->seek(0); @@ -36,11 +35,13 @@ $state = preg_replace('@^\s+@', '', $state); $state = preg_replace('@\s+$@', '', $state); - /* (3) Check data */ + /* (3) Free file descriptor */ + + /* (4) Check data */ if( strlen($state) < 1 ) return false; - /* (4) Return global state */ + /* (5) Return global state */ return $state; } @@ -111,7 +112,6 @@ global $f_accesslog; /* (5) Update global state */ - global $f_gstate; $state = get_gstate(); // manage error @@ -211,8 +211,7 @@ /* (2) Update the state file */ - $f_gstate->seek(0); - $written = $f_gstate->fwrite($state); + $written = @file_put_contents(STATE_CONF, $state); /* (3) Manage error */ if( $written === false ) @@ -251,7 +250,7 @@ /* [0] Initialize global variables =========================================================*/ /* (1) File descriptiors */ - global $f_auth, $f_accesslog, $f_gstate; + global $f_auth, $f_accesslog; /* (2) Caches */ global $actions; @@ -263,7 +262,6 @@ /* (1) Read accesses */ $f_auth = new SplFileObject(AUTH_CONF, 'r'); $f_actions = new SplFileObject(ACTIONS_CONF, 'r'); - $f_gstate = new SplFileObject(STATE_CONF, 'r+'); /* (2) Append accesses (logs) */ $f_accesslog = new SplFileObject(DEFAULT_DATA, 'a');