Commit 8e8302dd authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

flatpak: address some memory leaks

Thanks valgrind!
parent cd0d8327
...@@ -574,7 +574,8 @@ public: ...@@ -574,7 +574,8 @@ public:
qWarning() << "No appstream dir for" << flatpak_remote_get_name(m_remote); qWarning() << "No appstream dir for" << flatpak_remote_get_name(m_remote);
return {}; return {};
} }
return QString::fromUtf8(g_file_get_path(appstreamDir)); g_autofree char *path_str = g_file_get_path(appstreamDir);
return QString::fromUtf8(path_str);
} }
QString name() const QString name() const
...@@ -603,7 +604,7 @@ bool FlatpakBackend::loadAppsFromAppstreamData(FlatpakInstallation *flatpakInsta ...@@ -603,7 +604,7 @@ bool FlatpakBackend::loadAppsFromAppstreamData(FlatpakInstallation *flatpakInsta
{ {
Q_ASSERT(flatpakInstallation); Q_ASSERT(flatpakInstallation);
GPtrArray *remotes = flatpak_installation_list_remotes(flatpakInstallation, m_cancellable, nullptr); g_autoptr(GPtrArray) remotes = flatpak_installation_list_remotes(flatpakInstallation, m_cancellable, nullptr);
if (!remotes) { if (!remotes) {
return false; return false;
} }
...@@ -614,7 +615,8 @@ bool FlatpakBackend::loadAppsFromAppstreamData(FlatpakInstallation *flatpakInsta ...@@ -614,7 +615,8 @@ bool FlatpakBackend::loadAppsFromAppstreamData(FlatpakInstallation *flatpakInsta
FlatpakRemote *remote = FLATPAK_REMOTE(g_ptr_array_index(remotes, i)); FlatpakRemote *remote = FLATPAK_REMOTE(g_ptr_array_index(remotes, i));
g_autoptr(GFile) fileTimestamp = flatpak_remote_get_appstream_timestamp(remote, flatpak_get_default_arch()); g_autoptr(GFile) fileTimestamp = flatpak_remote_get_appstream_timestamp(remote, flatpak_get_default_arch());
QFileInfo fileInfo = QFileInfo(QString::fromUtf8(g_file_get_path(fileTimestamp))); g_autofree char *path_str = g_file_get_path(fileTimestamp);
QFileInfo fileInfo = QFileInfo(QString::fromUtf8(path_str));
// Refresh appstream metadata in case they have never been refreshed or the cache is older than 6 hours // Refresh appstream metadata in case they have never been refreshed or the cache is older than 6 hours
if (!fileInfo.exists() || fileInfo.lastModified().toUTC().secsTo(QDateTime::currentDateTimeUtc()) > 21600) { if (!fileInfo.exists() || fileInfo.lastModified().toUTC().secsTo(QDateTime::currentDateTimeUtc()) > 21600) {
refreshAppstreamMetadata(flatpakInstallation, remote); refreshAppstreamMetadata(flatpakInstallation, remote);
...@@ -765,9 +767,7 @@ bool FlatpakBackend::loadInstalledApps(FlatpakInstallation *flatpakInstallation) ...@@ -765,9 +767,7 @@ bool FlatpakBackend::loadInstalledApps(FlatpakInstallation *flatpakInstallation)
void FlatpakBackend::loadLocalUpdates(FlatpakInstallation *flatpakInstallation) void FlatpakBackend::loadLocalUpdates(FlatpakInstallation *flatpakInstallation)
{ {
g_autoptr(GError) localError = nullptr; g_autoptr(GError) localError = nullptr;
g_autoptr(GPtrArray) refs = nullptr; g_autoptr(GPtrArray) refs = flatpak_installation_list_installed_refs(flatpakInstallation, m_cancellable, &localError);
refs = flatpak_installation_list_installed_refs(flatpakInstallation, m_cancellable, &localError);
if (!refs) { if (!refs) {
qWarning() << "Failed to get list of installed refs for listing updates:" << localError->message; qWarning() << "Failed to get list of installed refs for listing updates:" << localError->message;
return; return;
...@@ -932,12 +932,14 @@ bool FlatpakBackend::setupFlatpakInstallations(GError **error) ...@@ -932,12 +932,14 @@ bool FlatpakBackend::setupFlatpakInstallations(GError **error)
return true; return true;
} }
GPtrArray *installations = flatpak_get_system_installations(m_cancellable, error); g_autoptr(GPtrArray) installations = flatpak_get_system_installations(m_cancellable, error);
if (*error) { if (*error) {
qWarning() << "Failed to call flatpak_get_system_installations:" << (*error)->message; qWarning() << "Failed to call flatpak_get_system_installations:" << (*error)->message;
} }
for (uint i = 0; installations && i < installations->len; i++) { for (uint i = 0; installations && i < installations->len; i++) {
m_installations << FLATPAK_INSTALLATION(g_ptr_array_index(installations, i)); auto installation = FLATPAK_INSTALLATION(g_ptr_array_index(installations, i));
g_object_ref(installation);
m_installations << installation;
} }
auto user = flatpak_installation_new_user(m_cancellable, error); auto user = flatpak_installation_new_user(m_cancellable, error);
...@@ -1120,7 +1122,7 @@ void FlatpakBackend::onFetchSizeFinished(FlatpakResource *resource, guint64 down ...@@ -1120,7 +1122,7 @@ void FlatpakBackend::onFetchSizeFinished(FlatpakResource *resource, guint64 down
void FlatpakBackend::updateAppState(FlatpakResource *resource) void FlatpakBackend::updateAppState(FlatpakResource *resource)
{ {
FlatpakInstalledRef *ref = getInstalledRefForApp(resource->installation(), resource); g_autoptr(FlatpakInstalledRef) ref = getInstalledRefForApp(resource->installation(), resource);
if (ref) { if (ref) {
// If the app is installed, we can set information about commit, arch etc. // If the app is installed, we can set information about commit, arch etc.
updateAppInstalledMetadata(ref, resource); updateAppInstalledMetadata(ref, resource);
......
...@@ -532,7 +532,8 @@ QString FlatpakResource::installationPath() const ...@@ -532,7 +532,8 @@ QString FlatpakResource::installationPath() const
QString FlatpakResource::installationPath(FlatpakInstallation* flatpakInstallation) QString FlatpakResource::installationPath(FlatpakInstallation* flatpakInstallation)
{ {
g_autoptr(GFile) path = flatpak_installation_get_path(flatpakInstallation); g_autoptr(GFile) path = flatpak_installation_get_path(flatpakInstallation);
return QString::fromUtf8(g_file_get_path(path)); g_autofree char *path_str = g_file_get_path(path);
return QString::fromUtf8(path_str);
} }
QString FlatpakResource::installPath() const QString FlatpakResource::installPath() const
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment