浏览代码

* Cleanup session-specific variables because the session-instance can be re-used, bug #13287

git-svn-id: trunk@13022 -
joost 16 年之前
父节点
当前提交
24ce200737
共有 1 个文件被更改,包括 21 次插入11 次删除
  1. 21 11
      packages/fcl-web/src/websession.pp

+ 21 - 11
packages/fcl-web/src/websession.pp

@@ -57,6 +57,8 @@ Type
     FSessionDir: String;
     FSessionDir: String;
     FTerminated :Boolean;
     FTerminated :Boolean;
     SID : String;
     SID : String;
+  private
+    procedure FreeIniFile;
   Protected
   Protected
     Procedure CheckSession;
     Procedure CheckSession;
     Function GetSessionID : String; override;
     Function GetSessionID : String; override;
@@ -145,6 +147,13 @@ begin
   Result:=SID;
   Result:=SID;
 end;
 end;
 
 
+procedure TIniWebSession.FreeIniFile;
+begin
+  If Cached and Assigned(FIniFile) then
+    TMemIniFile(FIniFile).UpdateFile;
+  FreeAndNil(FIniFile);
+end;
+
 Procedure TIniWebSession.CheckSession;
 Procedure TIniWebSession.CheckSession;
 
 
 begin
 begin
@@ -173,9 +182,9 @@ end;
 
 
 destructor TIniWebSession.Destroy;
 destructor TIniWebSession.Destroy;
 begin
 begin
-  If Cached and Assigned(FIniFile) then
-    TMemIniFile(FIniFile).UpdateFile;
-  FreeAndNil(FIniFile);
+  // In case an exception occured and UpdateResponse is not called,
+  // write the updates to disk and free FIniFile
+  FreeIniFile;
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
@@ -192,8 +201,7 @@ end;
 procedure TIniWebSession.UpdateResponse(AResponse: TResponse);
 procedure TIniWebSession.UpdateResponse(AResponse: TResponse);
 begin
 begin
   // Do nothing. Init has done the job.
   // Do nothing. Init has done the job.
-  If Cached and Assigned(FIniFile) then
-    TMemIniFile(FIniFile).UpdateFile;
+  FreeIniFile;
 end;
 end;
 
 
 procedure TIniWebSession.InitSession(ARequest: TRequest; OnNewSession,OnExpired: TNotifyEvent);
 procedure TIniWebSession.InitSession(ARequest: TRequest; OnNewSession,OnExpired: TNotifyEvent);
@@ -204,6 +212,14 @@ Var
   S : String;
   S : String;
 begin
 begin
 {$ifdef cgidebug}SendMethodEnter('TIniWebSession.InitSession');{$endif}
 {$ifdef cgidebug}SendMethodEnter('TIniWebSession.InitSession');{$endif}
+  // First initialize all session-dependent properties to their default, because
+  // in Apache-modules or fcgi programs the session-instance is re-used
+  SID := '';
+  FSessionStarted := False;
+  FTerminated := False;
+  // If a exception occured during a prior request FIniFile is still not freed
+  if assigned(FIniFile) then FreeIniFile;
+
   If (SessionCookie='') then
   If (SessionCookie='') then
     SessionCookie:=SFPWebSession;
     SessionCookie:=SFPWebSession;
   S:=ARequest.CookieFields.Values[SessionCookie];
   S:=ARequest.CookieFields.Values[SessionCookie];
@@ -324,16 +340,10 @@ end;
 
 
 procedure TSessionHTTPModule.CheckSession(ARequest : TRequest);
 procedure TSessionHTTPModule.CheckSession(ARequest : TRequest);
 
 
-Var
-  S : TCustomSession;
-
 begin
 begin
 {$ifdef cgidebug}SendMethodEnter('SessionHTTPModule('+Name+').CheckSession');{$endif}
 {$ifdef cgidebug}SendMethodEnter('SessionHTTPModule('+Name+').CheckSession');{$endif}
   If CreateSession and Assigned(FSession) then
   If CreateSession and Assigned(FSession) then
-    begin
-    S:=FSession;
     FSession.InitSession(ARequest,FOnNewSession,FOnSessionExpired);
     FSession.InitSession(ARequest,FOnNewSession,FOnSessionExpired);
-    end;
 {$ifdef cgidebug}SendMethodExit('SessionHTTPModule('+Name+').CheckSession');{$endif}
 {$ifdef cgidebug}SendMethodExit('SessionHTTPModule('+Name+').CheckSession');{$endif}
 end;
 end;