Details
Description
When setting the cache with QNetworkAccessManager.setCache() the passed cache object does get cleaned up if the caller does not keep a reference to the object. It would be expected that passing the cache object to QNetworkAccessManager.setCache() would keep the object alive, as the documentation for QNetworkAccessManager.setCache() states:
Note: QNetworkAccessManager takes ownership of the cache object.
The below code shows the principle. A full runnable reproducer is attached with main.py
class SomeClass(QtCore.QObject): def __init__(self): super().__init__() self.access_manager = QtNetwork.QNetworkAccessManager() cache = QtNetwork.QNetworkDiskCache() self.access_manager.setCache(cache) # Uncommenting the below line would prevent the segfault, # but this should not be needed. # self.cache = cache def run(self): request = QtNetwork.QNetworkRequest(QtCore.QUrl("http://qt-project.org")) # The application will segfault in the next call self.access_manager.get(request)
I tested and reproduced the issue with PySide 6.7.0 and 6.6.3.1