Qt: fix crash when opening/saving IP map on Windows

According to https://bugreports.qt.io/browse/QTBUG-20372 you need to close
a QFile before calling fclose, otherwise it leads to an unexpected behavior.
Let's duplicate the file handle to avoid this issue as suggested in
https://stackoverflow.com/questions/9465727/convert-qfile-to-file

Closes #17074
This commit is contained in:
Pascal Quantin 2020-12-12 12:27:51 +01:00 committed by Wireshark GitLab Utility
parent e2e43c0a8a
commit 746051d099
1 changed files with 2 additions and 1 deletions

View File

@ -223,7 +223,8 @@ QUrl EndpointDialog::createMap(bool json_only)
g_free(hosts);
return QUrl();
}
FILE* fp = ws_fdopen(fd, "wb");
// duplicate file descriptor as it is not allowed to perform a fclose before closing QFile
FILE* fp = ws_fdopen(ws_dup(fd), "wb");
if (fp == NULL) {
QMessageBox::warning(this, tr("Map file error"), tr("Unable to create temporary file"));
g_free(hosts);