bugGNU Octave - Bugs: bug #49197, xmlread in IO-pkg - open file...

 
 

bug #49197: xmlread in IO-pkg - open file handles

Submitter:  None
Submitted:  Tue 27 Sep 2016 09:31:22 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Performance
Status:  Fixed Assigned to:  philipnienhuis
Originator Name:  Tobi Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * other
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 03 Oct 2016 08:14:04 PM UTC, comment #8: 

@Pantxo: Thanks for the cset, pushed here:
http://hg.code.sf.net/p/octave/io/rev/c6f62ab6e7b1

In addition I pushed similar fixes for the POI and OXS interfaces.

Closing report.

Philip Nienhuis <philipnienhuis>
Group Member
Wed 28 Sep 2016 02:58:23 PM UTC, comment #7: 

@OP:
Well I meant Octave file handles opened with fopen(), not so much Java file handles.
Those Octave handles can be (should be) closed explicitly with fclose() but many functions don't do that in case of errors, notably in test blocks - some core Octave functions included.

[Slightly OT]
It can get worse though. In the UNO interface for spreadsheet I/O (invoking LibreOffice behind the scenes) open file connections left dangling when the function invoking them crashes will simply make it impossible to close Octave gracefully. First the hidden soffice.bin processes (=LibreOffice) will have to be killed manually, only then Octave can be exited.
The relevant UNO spreadsheet I/O scripts include unwind_protect / try-catch blocks at the relevant places to at least make sure Octave can be exited.

@Pantxo, thank you very much, I'll have a look at your patch asap.

Philip Nienhuis <philipnienhuis>
Group Member
Wed 28 Sep 2016 07:42:08 AM UTC, comment #6: 

"At the OP: I think you're mixing up xmlread.m and xmlwrite.m :-)"

oh yes.. my bad.

"But I know that Octave file handles not explicitly closed in functions remain open until closure of Octave itself."

yes, this is exactly my problem. I can't delete my files before i close octave or delete the handle.

Anonymous
Tue 27 Sep 2016 09:55:56 PM UTC, comment #5: 

I attached a patch. The unwind_protect enclosing try/catch blocks looks hacky but as I don't know a proper way to handle java exceptions I can't think of a better method. I used "ls -l /proc/OCTAVEPID/fd" to check the file was now properly closed.



(file #38611)

Pantxo Diribarne <pantxo>
Group Member
Tue 27 Sep 2016 06:52:56 PM UTC, comment #4: 

At the OP: I think you're mixing up xmlread.m and xmlwrite.m :-)

Pantxo, if you could supply a cset, please do.
I'll have a check of the spreadsheet interfaces where similar constructs live.

BTW I figured that when an Octave function is finished, Octave clears all variables and objects created in the function, right?
That should also apply to Java objects.

But I know that Octave file handles not explicitly closed in functions remain open until closure of Octave itself.

Philip Nienhuis <philipnienhuis>
Group Member
Tue 27 Sep 2016 05:50:59 PM UTC, comment #3: 

I agree that the files stream should be closed, so simply applying the Tobi's solution is the way to go. We should probably also enclose all relevant code in an unwind_protect block to ensure the file stream is closed even if an error occurs. I can prepare a cset if needed.

Pantxo Diribarne <pantxo>
Group Member
Tue 27 Sep 2016 04:16:47 PM UTC, comment #2: 

Adding Pantxo in turn (it's his code).

(release -> other (it's not core Octave)

Philip Nienhuis <philipnienhuis>
Group Member
Tue 27 Sep 2016 11:15:18 AM UTC, comment #1: 

Added package maintainer.

Kai Torben Ohlhus <siko1056>
Group Member
Tue 27 Sep 2016 09:31:22 AM UTC, original submission:  

in xmlread.m line 91:
    jos = javaObject ("java.io.FileOutputStream", jfile);

opens a file handle, but this handle will never close.

under line 123 in xmlrad.m, i would add
    jos.close();


I'm not a javaexpert, but it works fine for my application.
I checked the open file handles with "Process Explorer".

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #38611:  close_os.patch added by pantxo (3KiB - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by philipnienhuis
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by siko1056 (Package maintainer.)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-10-03 philipnienhuis StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2016-10-03 philipnienhuis StatusConfirmed In Progress
        Assigned toNone philipnienhuis
    2016-09-27 pantxo Attached File- Added close_os.patch, #38611
    2016-09-27 philipnienhuis Operating SystemMicrosoft Windows Any
    2016-09-27 pantxo StatusNone Confirmed
    2016-09-27 philipnienhuis Assigned tophilipnienhuis None
        Release4.0.3 other
        Carbon-Copy- Added pantxo
    2016-09-27 siko1056 Assigned toNone philipnienhuis
        Carbon-Copy- Added philipnienhuis

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code