summaryrefslogtreecommitdiff
path: root/vfs/UVFSCore.pas
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2009-10-04 16:27:34 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2009-10-04 16:27:34 +0200
commit9edcc05f98afb705071e9a906492aaf4d3a10160 (patch)
tree0a92d5d175931b3941b494ff47405dc1f5e97835 /vfs/UVFSCore.pas
parentcf1f8d377549c6cb5ad9475dcd5ec5f48738a8e8 (diff)
downloadtuxcmd-9edcc05f98afb705071e9a906492aaf4d3a10160.tar.xz
Consolidate VFS memory managementv0.6.66
Diffstat (limited to 'vfs/UVFSCore.pas')
-rw-r--r--vfs/UVFSCore.pas94
1 files changed, 79 insertions, 15 deletions
diff --git a/vfs/UVFSCore.pas b/vfs/UVFSCore.pas
index 7c98303..45bfc83 100644
--- a/vfs/UVFSCore.pas
+++ b/vfs/UVFSCore.pas
@@ -189,6 +189,7 @@ end;
(********************************************************************************************************************************)
constructor TVFSPlugin.Create(PluginHandle: Pointer);
+var s: PChar;
begin
inherited Create;
ModuleHandle := PluginHandle;
@@ -235,11 +236,24 @@ begin
@FVFSGetPasswordRequired := dlsym(ModuleHandle, 'VFSGetPasswordRequired');
@FVFSSetCallbacks := dlsym(ModuleHandle, 'VFSSetCallbacks');
@FVFSResetPassword := dlsym(ModuleHandle, 'VFSResetPassword');
+
// Initialize the extensions list
SetLength(Extensions, 0);
SetLength(Services, 0);
- if @FVFSGetExts <> nil then ParseString(FVFSGetExts, ';', Extensions);
- if @FVFSGetServices <> nil then ParseString(FVFSGetServices, ';', Services);
+ if @FVFSGetExts <> nil then begin
+ s := FVFSGetExts;
+ if s <> nil then begin
+ ParseString(String(s), ';', Extensions);
+ libc_free(s);
+ end;
+ end;
+ if @FVFSGetServices <> nil then begin
+ s := FVFSGetServices;
+ if s <> nil then begin
+ ParseString(String(s), ';', Services);
+ libc_free(s);
+ end;
+ end;
end;
destructor TVFSPlugin.Destroy;
@@ -257,39 +271,53 @@ begin
else Result := -1;
end;
+procedure _free_PVFSInfo(Info: PVFSInfo);
+begin
+ if Info <> nil then begin
+ if Info^.Name <> nil then libc_free(Info^.Name);
+ if Info^.ID <> nil then libc_free(Info^.ID);
+ if Info^.About <> nil then libc_free(Info^.About);
+ if Info^.Copyright <> nil then libc_free(Info^.Copyright);
+ end;
+end;
+
function TVFSPlugin.ModuleID: string;
-var Info: TVFSInfo;
+var Info: PVFSInfo;
begin
if @FVFSGetInfo <> nil then begin
Info := FVFSGetInfo;
Result := String(Info.ID);
+ _free_PVFSInfo(Info);
end else Result := '';
end;
function TVFSPlugin.ModuleName: string;
-var Info: TVFSInfo;
+var Info: PVFSInfo;
begin
if @FVFSGetInfo <> nil then begin
Info := FVFSGetInfo;
Result := String(Info.Name);
+ _free_PVFSInfo(Info);
end else Result := '';
end;
function TVFSPlugin.ModuleAbout: string;
-var Info: TVFSInfo;
+var Info: PVFSInfo;
begin
if @FVFSGetInfo <> nil then begin
Info := FVFSGetInfo;
Result := String(Info.About);
+ _free_PVFSInfo(Info);
end else Result := '';
end;
function TVFSPlugin.ModuleCopyright: string;
-var Info: TVFSInfo;
+var Info: PVFSInfo;
begin
if @FVFSGetInfo <> nil then begin
Info := FVFSGetInfo;
Result := String(Info.Copyright);
+ _free_PVFSInfo(Info);
end else Result := '';
end;
@@ -425,6 +453,9 @@ begin
DebugMsg(['^^VFS (EE): GetListing: Item-Exception: ', E.Message]);
end;
end; // of if AddDotFiles
+ if P^.FName <> nil then libc_free(P^.FName);
+ if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
libc_free(P); // Not needed - just zero-erase the memory
// DebugMsg(['Checkpoint 13']);
P := malloc(SizeOf(TVFSItem));
@@ -505,26 +536,41 @@ begin
end;
function TVFSEngine.GetPrefix: string;
+var s: PChar;
begin
- if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetPrefix <> nil)
- then Result := FSourcePlugin.FVFSGetPrefix(FGlobs)
- else Result := 'VFS';
+ Result := 'VFS';
+ if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetPrefix <> nil) then begin
+ s := FSourcePlugin.FVFSGetPrefix(FGlobs);
+ if s <> nil then begin
+ Result := String(s);
+ libc_free(s);
+ end;
+ end;
end;
function TVFSEngine.GetPath: string;
+var s: PChar;
begin
- if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetPath <> nil)
- then Result := FSourcePlugin.FVFSGetPath(FGlobs)
- else Result := '/';
+ Result := '/';
+ if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetPath <> nil) then begin
+ s := FSourcePlugin.FVFSGetPath(FGlobs);
+ if s <> nil then begin
+ Result := String(s);
+ libc_free(s);
+ end;
+ end;
end;
function TVFSEngine.GetPathURI: string;
-var x: PChar;
+var s: PChar;
begin
Result := '';
if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetPathURI <> nil) then begin
- x := FSourcePlugin.FVFSGetPathURI(FGlobs);
- if x <> nil then Result := string(x);
+ s := FSourcePlugin.FVFSGetPathURI(FGlobs);
+ if s <> nil then begin
+ Result := String(s);
+ libc_free(s);
+ end;
end;
end;
@@ -624,6 +670,9 @@ begin
GID := P^.iGID;
Size := P^.iSize;
PackedSize := P^.iPackedSize;
+ if P^.FName <> nil then libc_free(P^.FName);
+ if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
libc_free(P);
end;
Result := Item;
@@ -704,6 +753,9 @@ begin
Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P);
if Res <> cVFS_OK then DebugMsg(['*** FillDirFiles - VFSFileInfo(', APath, ') failed. Code = ', Res]);
AddEntry(APath, True, True);
+ if P^.FName <> nil then libc_free(P^.FName);
+ if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
libc_free(P);
APath := IncludeTrailingPathDelimiter(APath);
@@ -717,6 +769,9 @@ begin
Res := FSourcePlugin.FVFSListFirst(FGlobs, PChar(APath), P);
if Res <> cVFS_OK then begin
FSourcePlugin.FVFSListClose(FGlobs);
+ if P^.FName <> nil then libc_free(P^.FName);
+ if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
libc_free(P);
Exit;
end;
@@ -725,12 +780,18 @@ begin
if TVFSItemType(P^.ItemType) = vDirectory
then LocalList.Add(APath + String(P^.FName))
else AddEntry(APath + String(P^.FName), False, True);
+ if P^.FName <> nil then libc_free(P^.FName);
+ if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
libc_free(P);
P := malloc(SizeOf(TVFSItem));
memset(P, 0, SizeOf(TVFSItem));
Res := FSourcePlugin.FVFSListNext(FGlobs, PChar(GetPath), P);
until (Res <> cVFS_OK);
+ if P^.FName <> nil then libc_free(P^.FName);
+ if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
libc_free(P);
FSourcePlugin.FVFSListClose(FGlobs);
@@ -750,6 +811,9 @@ begin
Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P);
if Res <> cVFS_OK then DebugMsg(['*** FillDirFiles - VFSFileInfo(', APath, ') failed. Code = ', Res]);
AddEntry(APath, True, False);
+ if P^.FName <> nil then libc_free(P^.FName);
+ if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
libc_free(P);
LocalList.Free;