Skip to content

Commit a82bd03

Browse files
committed
Don't close file in vcard::fromDevice on read failure
1 parent f0b57f5 commit a82bd03

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/xmpp/xmpp-im/xmpp_vcard4.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -715,29 +715,29 @@ VCard VCard::fromFile(const QString &filename)
715715
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
716716
return VCard();
717717

718-
return fromFile(file);
718+
auto vcard = fromDevice(&file);
719+
file.close();
720+
return vcard;
719721
}
720722

721-
VCard VCard::fromFile(QFile &file)
723+
VCard VCard::fromDevice(QIODevice *dev)
722724
{
723725
QDomDocument doc;
724726
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
725-
if (!doc.setContent(&file, true)) {
727+
if (!doc.setContent(dev, true)) {
726728
#else
727-
if (!doc.setContent(&file, QDomDocument::ParseOption::UseNamespaceProcessing)) {
729+
if (!doc.setContent(dev, QDomDocument::ParseOption::UseNamespaceProcessing)) {
728730
#endif
729-
file.close();
730-
return VCard();
731+
return {};
731732
}
732-
file.close();
733733

734734
QDomElement root = doc.documentElement();
735735
if (root.tagName() != QLatin1String("vcards") || root.namespaceURI() != VCARD_NAMESPACE)
736-
return VCard();
736+
return {};
737737

738738
QDomElement vCardElement = root.firstChildElement(QLatin1String("vcard"));
739739
if (vCardElement.isNull())
740-
return VCard();
740+
return {};
741741

742742
return VCard(vCardElement);
743743
}

src/xmpp/xmpp-im/xmpp_vcard4.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class VCard {
252252
QDomElement toXmlElement(QDomDocument &document) const;
253253

254254
static VCard fromFile(const QString &filename);
255-
static VCard fromFile(QFile &file);
255+
static VCard fromDevice(QIODevice *dev);
256256
bool save(const QString &filename) const;
257257

258258
void fromVCardTemp(const XMPP::VCard &tempVCard);

0 commit comments

Comments
 (0)