Comment 11 for bug 1899193

Revision history for this message
Julian Andres Klode (juliank) wrote :

Attached is a patch for the error cases in debfile_new (and ArArchive and TagFile). It works by decreasing the reference count of the object on error paths, and clearing the cycles, so that the object will be collected and the FD released once the function returns.

A test case will be added shortly, that will do os.listdir(/proc/self/fd) before and after calls to ensure that the number of file descriptors is the same.

Because the reason it needed a GC run before was: It turns out I do have cycles in both DebFile and TagFile:

DebFile contains references to data.tar and control.tar members, which in point hold references to the DebFile, so as to make sure that the file stays around while the data needs it.

TagFile links to a TagSection which links back to the TagFile, as the data is actually stored in the tagfile buffer. Oh dear.

I suppose I could fix them both correctly by removing the cycle, e.g. abstracting the File to a FileCommon that both File and Section/member reference, then existing code relying on reference counts will start behaving correctly.