#1 2023-05-01 21:08:35

tbo
Member
Registered: 2015-04-20
Posts: 335

Unit mormot.lib.win7zip, memory leak

Delphi 11.3, mORMot2 GitHub commit 5395 (bda0951)

1) Memory leak in function T7zWriter.AddBuffer. Must soOwned be used and not soReference.

procedure T7zWriter.AddBuffer(const ZipName: RawUtf8;
  const Data: RawByteString);
begin
  AddStream(TRawByteStringStream.Create(Data), soReference,  // <-- soOwned
    faArchive, 0, 0, ZipName, false, false);
end;

2) In function T7zWriter.AddStream should be written:

...
item.Stream := Stream;
// item.Size := Stream.Size;
if Stream <> Nil then
  item.Size := Stream.Size;

3) Can an T7zWriter.AddDirectory function be added?

With best regards
Thomas

Offline

#2 2023-05-02 02:56:19

igors233
Member
Registered: 2012-09-10
Posts: 234

Re: Unit mormot.lib.win7zip, memory leak

I've created 7z wrapper years ago, it supports more of 7z options (GetNumberOfFormats, GetHandlerProperty2, self extracting). To create dir in 7z you have to pass empty file name, perhaps if you expose T7zWriter.AddOrReplace it could be done.

Here's my code in case someone want's to add more functionality to this implementation:
https://www.dropbox.com/s/iszoge0frqocf … er.7z?dl=0

Last edited by igors233 (2023-05-02 02:59:56)

Offline

#3 2023-05-02 07:22:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Unit mormot.lib.win7zip, memory leak

@thomas
Please try https://github.com/synopse/mORMot2/commit/72799230
Thanks for the report.

@igors233
Nice wrapper!
You should have published it on github as reference - it would have helped me, and may help others. wink

Offline

#4 2023-05-04 10:03:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Unit mormot.lib.win7zip, memory leak

There was no leak I am afraid. The TRawByteStream was properly released.
With your soReference modification, I have an access violation now during normal process.

So I have reverted the change with
https://github.com/synopse/mORMot2/commit/cbcf0e1d
I have checked with FastMM4 in fulldebugmode that it does not show any memory leak.

Offline

#5 2023-05-04 13:16:01

tbo
Member
Registered: 2015-04-20
Posts: 335

Re: Unit mormot.lib.win7zip, memory leak

ab wrote:

There was no leak I am afraid. The TRawByteStream was properly released.
With your soReference modification, I have an access violation now during normal process.

You're right. Sorry, didn't test properly there. That works:

libWriter.AddStream(TRawByteStringStream.Create(content), soReference, faArchive, 0, 0, 'TestFolder', false, false);

A stream with no content for any combination results in an memory leak:

libWriter.AddStream(TRawByteStringStream.Create(''), soReference {soOwned}, faDirectory, 0, 0, 'TestFolder', True, False);

This error message is displayed:

An unexpected memory leak has occurred. The unexpected small block leaks are:
21 - 28 bytes: TRawByteStringStream x 1

Without content it only works properly with soOwned. That was the thread that triggered this post.

With best regards
Thomas

Offline

#6 2023-05-04 14:22:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Unit mormot.lib.win7zip, memory leak

Offline

#7 2023-05-04 15:21:21

tbo
Member
Registered: 2015-04-20
Posts: 335

Re: Unit mormot.lib.win7zip, memory leak

With Commit 5420 (e4ccc8e), it behaves as expected in my tests. Thanks a lot for that.

With best regards
Thomas

Offline

Board footer

Powered by FluxBB