[tracker-miners/wip/carlosg/coverity-fixes: 20/28] cli: Plug leak
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/coverity-fixes: 20/28] cli: Plug leak
- Date: Sun, 24 Oct 2021 11:33:39 +0000 (UTC)
commit a07e92b286c5a5d9cc8d725ca82247b5467f8554
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Oct 24 12:02:40 2021 +0200
cli: Plug leak
When printing turtle in "tracker info", the "subject" string was
being leaked and unused. Avoid it, and fix use of shorthands in
turtle subjects.
CID: #370569
src/tracker/tracker-info.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
---
diff --git a/src/tracker/tracker-info.c b/src/tracker/tracker-info.c
index da85ed2bf..72f71ee59 100644
--- a/src/tracker/tracker-info.c
+++ b/src/tracker/tracker-info.c
@@ -308,23 +308,16 @@ print_turtle (gchar *urn,
GHashTable *prefixes,
gboolean full_namespaces)
{
- gchar *subject;
gchar *predicate;
gchar *object;
gboolean has_output = FALSE;
- if (G_UNLIKELY (full_namespaces)) {
- subject = g_strdup (urn);
- } else {
- /* truncate subject */
- subject = tracker_sparql_get_shorthand (prefixes, urn);
- }
-
while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
const gchar *key = tracker_sparql_cursor_get_string (cursor, 0, NULL);
const gchar *value = tracker_sparql_cursor_get_string (cursor, 1, NULL);
const gchar *subject_value = tracker_sparql_cursor_get_string (cursor, 2, NULL);
const gchar *is_resource = tracker_sparql_cursor_get_string (cursor, 3, NULL);
+ gchar *subject_shorthand = NULL;
if (!key || !value || !is_resource) {
continue;
@@ -350,18 +343,23 @@ print_turtle (gchar *urn,
g_free (escaped_value);
}
- if (subject_value)
- subject = g_strdup (subject_value);
-
/* Print final statement */
- g_print ("<%s> %s %s .\n", subject, predicate, object);
+ if (G_LIKELY (!full_namespaces)) {
+ /* truncate subject */
+ subject_shorthand = tracker_sparql_get_shorthand (prefixes, subject_value);
+ }
+ if (subject_shorthand && g_strcmp0 (subject_value, subject_shorthand) != 0) {
+ g_print ("%s %s %s .\n", subject_shorthand, predicate, object);
+ } else {
+ g_print ("<%s> %s %s .\n", subject_value, predicate, object);
+ }
+
+ g_free (subject_shorthand);
g_free (predicate);
g_free (object);
}
- g_free (subject);
-
return has_output;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]