Bug 694859 - tiffsep leaves handle open on main generated composite file when called from within code in .net
Summary: tiffsep leaves handle open on main generated composite file when called from ...
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Client API (show other bugs)
Version: 9.10
Hardware: PC Windows 7
: P4 normal
Assignee: Ken Sharp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-20 05:03 UTC by Alex
Modified: 2023-05-18 08:44 UTC (History)
3 users (show)

See Also:
Customer:
Word Size: ---


Attachments
A sample program that uses GS API (1.04 KB, text/plain)
2021-02-09 21:03 UTC, Peter Cherepanov
Details
One-page sample with spot colors. (187 bytes, application/postscript)
2021-02-09 21:05 UTC, Peter Cherepanov
Details
Two-page sample with spot colors (370 bytes, application/postscript)
2021-02-09 21:06 UTC, Peter Cherepanov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex 2013-12-20 05:03:23 UTC
I am using a gsdll32.dll wrapper as described here
http://stackoverflow.com/questions/16929383/simple-vb-net-wrapper-for-ghostscript-dll
It works perfectly, except for tiffsep device. The device creates all the files ok, everything is ok for the separation files, except on the main composite preview file it leaves a handle open so the subsequent delete in my code fails on the file. Nevertheless, a subsequent call of gsdll with tiffsep with the same output file name from within the code works, but there is yet another handle left open on the main composite preview file.

With another device, like tiff24nc, all works fine, the file produced by gsdll32.dll are not locked by any handle.
Comment 1 Peter Cherepanov 2021-02-09 21:03:45 UTC
Created attachment 20589 [details]
A sample program that uses GS API

This demo program is the Example 1 from API.htm with some minor changes. Although it is not an original VB program, it demonstrates a similar problem: some of the separations are not closed. However, current version of Ghostscript does not close spot separations, rather than the composite file.

The problem is caused by zeroing num_separations
void free_separation_names( ){
  // ...
  pseparation->num_separations = 0;
}
which is later used to calculate the number of available separations. Deletion of this line does not work, because this causes accumulation of separations with empty names.
Comment 2 Peter Cherepanov 2021-02-09 21:05:16 UTC
Created attachment 20590 [details]
One-page sample with spot colors.
Comment 3 Peter Cherepanov 2021-02-09 21:06:05 UTC
Created attachment 20591 [details]
Two-page sample with spot colors
Comment 4 Ken Sharp 2023-05-18 08:44:27 UTC
In the initial report Alex has not specified the arguments being used, however assuming a single fixed filename (eg output.tif) this is expected behaviour. This is the way that Peter's example test harness is constructed.

The reason is that the device doesn't close the file at the end of the page when there is a single file, it simply reuses it for the next page. The file is only closed when the device is closed.

There are several ways to address this. Most simply is to use a format specifier such as "output%d.tif" for the filename. Alternatively you can open the device through PostScript and save/restore around the device selection. Deactivating the device with a restore will close the file. Finally you can use the (undocumented!) ReopenPerPage parameter. This will close the file after the end of the page. A subsequent page will open the file with the same name, but it will get a new file handle.

Previously this would close the composite file, but not the separation files, which isn't really adequate. I have made a commit here:

e9a5d8b623d489478a0091ad7ef9ef13c57cf1d6

which will also close the separation files at the end of the page if ReopenPerPage is true. I've also asked our documentation maintainer to update the documentation with this parameter.

I'm closing this as fixed, because I've made a commit, though really it's more invalid or worksforme because the behaviourt is expected.