Skip to content

Commit

Permalink
Don't close file in vcard::fromDevice on read failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jun 12, 2024
1 parent f0b57f5 commit a82bd03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/xmpp/xmpp-im/xmpp_vcard4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,29 +715,29 @@ VCard VCard::fromFile(const QString &filename)
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return VCard();

return fromFile(file);
auto vcard = fromDevice(&file);
file.close();
return vcard;
}

VCard VCard::fromFile(QFile &file)
VCard VCard::fromDevice(QIODevice *dev)
{
QDomDocument doc;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (!doc.setContent(&file, true)) {
if (!doc.setContent(dev, true)) {
#else
if (!doc.setContent(&file, QDomDocument::ParseOption::UseNamespaceProcessing)) {
if (!doc.setContent(dev, QDomDocument::ParseOption::UseNamespaceProcessing)) {
#endif
file.close();
return VCard();
return {};
}
file.close();

QDomElement root = doc.documentElement();
if (root.tagName() != QLatin1String("vcards") || root.namespaceURI() != VCARD_NAMESPACE)
return VCard();
return {};

QDomElement vCardElement = root.firstChildElement(QLatin1String("vcard"));
if (vCardElement.isNull())
return VCard();
return {};

return VCard(vCardElement);
}
Expand Down
2 changes: 1 addition & 1 deletion src/xmpp/xmpp-im/xmpp_vcard4.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class VCard {
QDomElement toXmlElement(QDomDocument &document) const;

static VCard fromFile(const QString &filename);
static VCard fromFile(QFile &file);
static VCard fromDevice(QIODevice *dev);
bool save(const QString &filename) const;

void fromVCardTemp(const XMPP::VCard &tempVCard);
Expand Down

0 comments on commit a82bd03

Please sign in to comment.