[tracker/pdfmem-for-master] tracker-extract: Avoid a strdup of some memory in PDF extractor
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/pdfmem-for-master] tracker-extract: Avoid a strdup of some memory in PDF extractor
- Date: Thu, 29 Apr 2010 14:35:54 +0000 (UTC)
commit 5faa8162005bee7e5a1bd8e25c58f0d8c9f9ab9c
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Apr 29 16:34:36 2010 +0200
tracker-extract: Avoid a strdup of some memory in PDF extractor
src/tracker-extract/tracker-extract-pdf.cpp | 331 +++++++++++++--------------
1 files changed, 164 insertions(+), 167 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-pdf.cpp b/src/tracker-extract/tracker-extract-pdf.cpp
index 0441569..d812bd4 100644
--- a/src/tracker-extract/tracker-extract-pdf.cpp
+++ b/src/tracker-extract/tracker-extract-pdf.cpp
@@ -499,7 +499,6 @@ extract_pdf (const gchar *uri,
PDFData pd = { 0 }; /* actual data */
PDFData md = { 0 }; /* for merging */
PDFDoc *document;
- gchar *xml = NULL;
gchar *content;
guint n_words;
Object obj;
@@ -559,223 +558,221 @@ extract_pdf (const gchar *uri,
}
obj.free ();
+
catalog = document->getCatalog ();
if (catalog && catalog->isOk ()) {
GooString *s = catalog->readMetadata ();
if ( s != NULL ) {
- xml = g_strdup (s->getCString());
- delete s;
- }
- }
+ const gchar *xml;
- if (xml) {
- xd = tracker_xmp_new (xml, strlen (xml), uri);
+ xml = s->getCString();
+ xd = tracker_xmp_new (xml, strlen (xml), uri);
- if (!xd) {
- xd = g_new0 (TrackerXmpData, 1);
- }
+ if (!xd) {
+ xd = g_new0 (TrackerXmpData, 1);
+ }
- g_free (xml);
- xml = NULL;
+ delete s;
- /* The casts here are well understood and known */
- md.title = (gchar *) tracker_coalesce_strip (3, pd.title, xd->title, xd->title2, xd->pdf_title);
- md.subject = (gchar *) tracker_coalesce_strip (2, pd.subject, xd->subject);
- md.date = (gchar *) tracker_coalesce_strip (3, pd.creation_date, xd->date, xd->time_original);
- md.author = (gchar *) tracker_coalesce_strip (2, pd.author, xd->creator);
+ /* The casts here are well understood and known */
+ md.title = (gchar *) tracker_coalesce_strip (3, pd.title, xd->title, xd->title2, xd->pdf_title);
+ md.subject = (gchar *) tracker_coalesce_strip (2, pd.subject, xd->subject);
+ md.date = (gchar *) tracker_coalesce_strip (3, pd.creation_date, xd->date, xd->time_original);
+ md.author = (gchar *) tracker_coalesce_strip (2, pd.author, xd->creator);
- write_pdf_data (md, metadata);
+ write_pdf_data (md, metadata);
- if (xd->keywords) {
- insert_keywords (metadata, xd->keywords);
- }
+ if (xd->keywords) {
+ insert_keywords (metadata, xd->keywords);
+ }
- if (xd->pdf_keywords) {
- insert_keywords (metadata, xd->pdf_keywords);
- }
+ if (xd->pdf_keywords) {
+ insert_keywords (metadata, xd->pdf_keywords);
+ }
- if (xd->publisher) {
- tracker_sparql_builder_predicate (metadata, "nco:publisher");
- tracker_sparql_builder_object_blank_open (metadata);
- tracker_sparql_builder_predicate (metadata, "a");
- tracker_sparql_builder_object (metadata, "nco:Contact");
- tracker_sparql_builder_predicate (metadata, "nco:fullname");
- tracker_sparql_builder_object_unvalidated (metadata, xd->publisher);
- tracker_sparql_builder_object_blank_close (metadata);
- }
+ if (xd->publisher) {
+ tracker_sparql_builder_predicate (metadata, "nco:publisher");
+ tracker_sparql_builder_object_blank_open (metadata);
+ tracker_sparql_builder_predicate (metadata, "a");
+ tracker_sparql_builder_object (metadata, "nco:Contact");
+ tracker_sparql_builder_predicate (metadata, "nco:fullname");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->publisher);
+ tracker_sparql_builder_object_blank_close (metadata);
+ }
- if (xd->type) {
- tracker_sparql_builder_predicate (metadata, "dc:type");
- tracker_sparql_builder_object_unvalidated (metadata, xd->type);
- }
+ if (xd->type) {
+ tracker_sparql_builder_predicate (metadata, "dc:type");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->type);
+ }
- if (xd->format) {
- tracker_sparql_builder_predicate (metadata, "dc:format");
- tracker_sparql_builder_object_unvalidated (metadata, xd->format);
- }
+ if (xd->format) {
+ tracker_sparql_builder_predicate (metadata, "dc:format");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->format);
+ }
- if (xd->identifier) {
- tracker_sparql_builder_predicate (metadata, "dc:identifier");
- tracker_sparql_builder_object_unvalidated (metadata, xd->identifier);
- }
+ if (xd->identifier) {
+ tracker_sparql_builder_predicate (metadata, "dc:identifier");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->identifier);
+ }
- if (xd->source) {
- tracker_sparql_builder_predicate (metadata, "dc:source");
- tracker_sparql_builder_object_unvalidated (metadata, xd->source);
- }
+ if (xd->source) {
+ tracker_sparql_builder_predicate (metadata, "dc:source");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->source);
+ }
- if (xd->language) {
- tracker_sparql_builder_predicate (metadata, "dc:language");
- tracker_sparql_builder_object_unvalidated (metadata, xd->language);
- }
+ if (xd->language) {
+ tracker_sparql_builder_predicate (metadata, "dc:language");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->language);
+ }
- if (xd->relation) {
- tracker_sparql_builder_predicate (metadata, "dc:relation");
- tracker_sparql_builder_object_unvalidated (metadata, xd->relation);
- }
+ if (xd->relation) {
+ tracker_sparql_builder_predicate (metadata, "dc:relation");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->relation);
+ }
- if (xd->coverage) {
- tracker_sparql_builder_predicate (metadata, "dc:coverage");
- tracker_sparql_builder_object_unvalidated (metadata, xd->coverage);
- }
+ if (xd->coverage) {
+ tracker_sparql_builder_predicate (metadata, "dc:coverage");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->coverage);
+ }
- if (xd->license) {
- tracker_sparql_builder_predicate (metadata, "nie:license");
- tracker_sparql_builder_object_unvalidated (metadata, xd->license);
- }
+ if (xd->license) {
+ tracker_sparql_builder_predicate (metadata, "nie:license");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->license);
+ }
- if (xd->make || xd->model) {
- gchar *camera;
+ if (xd->make || xd->model) {
+ gchar *camera;
- if ((xd->make == NULL || xd->model == NULL) ||
- (xd->make && xd->model && strstr (xd->model, xd->make) == NULL)) {
- camera = tracker_merge_const (" ", 2, xd->make, xd->model);
- } else {
- camera = g_strdup (xd->model);
+ if ((xd->make == NULL || xd->model == NULL) ||
+ (xd->make && xd->model && strstr (xd->model, xd->make) == NULL)) {
+ camera = tracker_merge_const (" ", 2, xd->make, xd->model);
+ } else {
+ camera = g_strdup (xd->model);
+ }
+
+ tracker_sparql_builder_predicate (metadata, "nmm:camera");
+ tracker_sparql_builder_object_unvalidated (metadata, camera);
+ g_free (camera);
}
- tracker_sparql_builder_predicate (metadata, "nmm:camera");
- tracker_sparql_builder_object_unvalidated (metadata, camera);
- g_free (camera);
- }
+ if (xd->orientation) {
+ tracker_sparql_builder_predicate (metadata, "nfo:orientation");
+ tracker_sparql_builder_object (metadata, xd->orientation);
+ }
- if (xd->orientation) {
- tracker_sparql_builder_predicate (metadata, "nfo:orientation");
- tracker_sparql_builder_object (metadata, xd->orientation);
- }
+ if (xd->rights) {
+ tracker_sparql_builder_predicate (metadata, "nie:copyright");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->rights);
+ }
- if (xd->rights) {
- tracker_sparql_builder_predicate (metadata, "nie:copyright");
- tracker_sparql_builder_object_unvalidated (metadata, xd->rights);
- }
+ if (xd->white_balance) {
+ tracker_sparql_builder_predicate (metadata, "nmm:whiteBalance");
+ tracker_sparql_builder_object (metadata, xd->white_balance);
+ }
- if (xd->white_balance) {
- tracker_sparql_builder_predicate (metadata, "nmm:whiteBalance");
- tracker_sparql_builder_object (metadata, xd->white_balance);
- }
+ if (xd->fnumber) {
+ gdouble value;
- if (xd->fnumber) {
- gdouble value;
+ value = g_strtod (xd->fnumber, NULL);
+ tracker_sparql_builder_predicate (metadata, "nmm:fnumber");
+ tracker_sparql_builder_object_double (metadata, value);
+ }
- value = g_strtod (xd->fnumber, NULL);
- tracker_sparql_builder_predicate (metadata, "nmm:fnumber");
- tracker_sparql_builder_object_double (metadata, value);
- }
+ if (xd->flash) {
+ tracker_sparql_builder_predicate (metadata, "nmm:flash");
+ tracker_sparql_builder_object (metadata, xd->flash);
+ }
- if (xd->flash) {
- tracker_sparql_builder_predicate (metadata, "nmm:flash");
- tracker_sparql_builder_object (metadata, xd->flash);
- }
+ if (xd->focal_length) {
+ gdouble value;
- if (xd->focal_length) {
- gdouble value;
+ value = g_strtod (xd->focal_length, NULL);
+ tracker_sparql_builder_predicate (metadata, "nmm:focalLength");
+ tracker_sparql_builder_object_double (metadata, value);
+ }
- value = g_strtod (xd->focal_length, NULL);
- tracker_sparql_builder_predicate (metadata, "nmm:focalLength");
- tracker_sparql_builder_object_double (metadata, value);
- }
+ /* Question: Shouldn't xd->Artist be merged with md.author instead? */
- /* Question: Shouldn't xd->Artist be merged with md.author instead? */
+ if (xd->artist || xd->contributor) {
+ const gchar *artist;
- if (xd->artist || xd->contributor) {
- const gchar *artist;
+ artist = tracker_coalesce_strip (2, xd->artist, xd->contributor);
+ tracker_sparql_builder_predicate (metadata, "nco:contributor");
+ tracker_sparql_builder_object_blank_open (metadata);
+ tracker_sparql_builder_predicate (metadata, "a");
+ tracker_sparql_builder_object (metadata, "nco:Contact");
+ tracker_sparql_builder_predicate (metadata, "nco:fullname");
+ tracker_sparql_builder_object_unvalidated (metadata, artist);
+ tracker_sparql_builder_object_blank_close (metadata);
+ }
- artist = tracker_coalesce_strip (2, xd->artist, xd->contributor);
- tracker_sparql_builder_predicate (metadata, "nco:contributor");
- tracker_sparql_builder_object_blank_open (metadata);
- tracker_sparql_builder_predicate (metadata, "a");
- tracker_sparql_builder_object (metadata, "nco:Contact");
- tracker_sparql_builder_predicate (metadata, "nco:fullname");
- tracker_sparql_builder_object_unvalidated (metadata, artist);
- tracker_sparql_builder_object_blank_close (metadata);
- }
+ if (xd->exposure_time) {
+ gdouble value;
- if (xd->exposure_time) {
- gdouble value;
+ value = g_strtod (xd->exposure_time, NULL);
+ tracker_sparql_builder_predicate (metadata, "nmm:exposureTime");
+ tracker_sparql_builder_object_double (metadata, value);
+ }
- value = g_strtod (xd->exposure_time, NULL);
- tracker_sparql_builder_predicate (metadata, "nmm:exposureTime");
- tracker_sparql_builder_object_double (metadata, value);
- }
+ if (xd->iso_speed_ratings) {
+ gdouble value;
- if (xd->iso_speed_ratings) {
- gdouble value;
+ value = g_strtod (xd->iso_speed_ratings, NULL);
+ tracker_sparql_builder_predicate (metadata, "nmm:isoSpeed");
+ tracker_sparql_builder_object_double (metadata, value);
+ }
- value = g_strtod (xd->iso_speed_ratings, NULL);
- tracker_sparql_builder_predicate (metadata, "nmm:isoSpeed");
- tracker_sparql_builder_object_double (metadata, value);
- }
+ if (xd->description) {
+ tracker_sparql_builder_predicate (metadata, "nie:description");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->description);
+ }
- if (xd->description) {
- tracker_sparql_builder_predicate (metadata, "nie:description");
- tracker_sparql_builder_object_unvalidated (metadata, xd->description);
- }
+ if (xd->metering_mode) {
+ tracker_sparql_builder_predicate (metadata, "nmm:meteringMode");
+ tracker_sparql_builder_object (metadata, xd->metering_mode);
+ }
- if (xd->metering_mode) {
- tracker_sparql_builder_predicate (metadata, "nmm:meteringMode");
- tracker_sparql_builder_object (metadata, xd->metering_mode);
- }
+ if (xd->address || xd->country || xd->city) {
+ tracker_sparql_builder_predicate (metadata, "mlo:location");
- if (xd->address || xd->country || xd->city) {
- tracker_sparql_builder_predicate (metadata, "mlo:location");
+ tracker_sparql_builder_object_blank_open (metadata);
+ tracker_sparql_builder_predicate (metadata, "a");
+ tracker_sparql_builder_object (metadata, "mlo:GeoPoint");
- tracker_sparql_builder_object_blank_open (metadata);
- tracker_sparql_builder_predicate (metadata, "a");
- tracker_sparql_builder_object (metadata, "mlo:GeoPoint");
+ if (xd->address) {
+ tracker_sparql_builder_predicate (metadata, "mlo:address");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->address);
+ }
- if (xd->address) {
- tracker_sparql_builder_predicate (metadata, "mlo:address");
- tracker_sparql_builder_object_unvalidated (metadata, xd->address);
- }
+ if (xd->state) {
+ tracker_sparql_builder_predicate (metadata, "mlo:state");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->state);
+ }
- if (xd->state) {
- tracker_sparql_builder_predicate (metadata, "mlo:state");
- tracker_sparql_builder_object_unvalidated (metadata, xd->state);
- }
+ if (xd->city) {
+ tracker_sparql_builder_predicate (metadata, "mlo:city");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->city);
+ }
- if (xd->city) {
- tracker_sparql_builder_predicate (metadata, "mlo:city");
- tracker_sparql_builder_object_unvalidated (metadata, xd->city);
- }
+ if (xd->country) {
+ tracker_sparql_builder_predicate (metadata, "mlo:country");
+ tracker_sparql_builder_object_unvalidated (metadata, xd->country);
+ }
- if (xd->country) {
- tracker_sparql_builder_predicate (metadata, "mlo:country");
- tracker_sparql_builder_object_unvalidated (metadata, xd->country);
+ tracker_sparql_builder_object_blank_close (metadata);
}
- tracker_sparql_builder_object_blank_close (metadata);
- }
-
- /* PDF keywords aren't used ATM (why not?) */
- g_free (pd.keywords);
+ /* PDF keywords aren't used ATM (why not?) */
+ g_free (pd.keywords);
- g_free (pd.title);
- g_free (pd.subject);
- g_free (pd.creation_date);
- g_free (pd.author);
- g_free (pd.date);
+ g_free (pd.title);
+ g_free (pd.subject);
+ g_free (pd.creation_date);
+ g_free (pd.author);
+ g_free (pd.date);
- tracker_xmp_free (xd);
+ tracker_xmp_free (xd);
+ }
} else {
/* So if we are here we have NO XMP data and we just
* write what we know from Poppler.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]