[gexiv2] gexiv2_metadata_get_gps_altitude(): Fix leak
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gexiv2] gexiv2_metadata_get_gps_altitude(): Fix leak
- Date: Sat, 30 Apr 2016 06:18:00 +0000 (UTC)
commit 6c7ebbd80a062d9fe699b3d956ac1dcaf9209668
Author: Roman Lebedev <lebedev ri gmail com>
Date: Fri Aug 28 17:03:11 2015 +0300
gexiv2_metadata_get_gps_altitude(): Fix leak
free return from gexiv2_metadata_get_exif_tag_string()
Fixes following AddressSanitizer issue:
Direct leak of 2 byte(s) in 1 object(s) allocated from:
#0 0x7f9de859c37a in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x9437a)
#1 0x7f9de5e8f799 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4f799)
#2 0x7f9de5ea812e in g_strdup (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x6812e)
#3 0x7f9de963f7ce in gexiv2_metadata_get_exif_tag_string gexiv2/gexiv2-metadata-exif.cpp:113
#4 0x7f9de9642cc6 in gexiv2_metadata_get_gps_altitude gexiv2/gexiv2-metadata-gps.cpp:178
#5 0x7f9de9642f2a in gexiv2_metadata_get_gps_info gexiv2/gexiv2-metadata-gps.cpp:216
#6 0x4172a1 in a_geotag_get_position /home/lebedevri/src/viking/src/geotag_exif.c:218
#7 0x4170b0 in main /home/lebedevri/src/viking/test/geotag_read.c:14
#8 0x7f9de26a1b44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b44)
#9 0x416fb8 (/home/lebedevri/src/viking/test/geotag_read+0x416fb8)
https://bugzilla.gnome.org/show_bug.cgi?id=754241
gexiv2/gexiv2-metadata-gps.cpp | 30 +++++++++++++++++++-----------
1 files changed, 19 insertions(+), 11 deletions(-)
---
diff --git a/gexiv2/gexiv2-metadata-gps.cpp b/gexiv2/gexiv2-metadata-gps.cpp
index 3c81255..51f1495 100644
--- a/gexiv2/gexiv2-metadata-gps.cpp
+++ b/gexiv2/gexiv2-metadata-gps.cpp
@@ -170,33 +170,41 @@ gboolean gexiv2_metadata_get_gps_altitude (GExiv2Metadata *self, gdouble *altitu
g_return_val_if_fail(GEXIV2_IS_METADATA (self), FALSE);
g_return_val_if_fail(altitude != NULL, FALSE);
g_return_val_if_fail(self->priv->image.get() != NULL, FALSE);
-
+
try {
double num, den;
*altitude = 0.0;
-
+
gchar* altitude_ref = gexiv2_metadata_get_exif_tag_string (self, "Exif.GPSInfo.GPSAltitudeRef");
- if (altitude_ref == NULL || altitude_ref[0] == '\0')
+ if (altitude_ref == NULL || altitude_ref[0] == '\0') {
+ g_free(altitude_ref);
return FALSE;
-
+ }
+
Exiv2::ExifData& exif_data = self->priv->image->exifData();
Exiv2::ExifKey key ("Exif.GPSInfo.GPSAltitude");
Exiv2::ExifData::iterator it = exif_data.findKey (key);
-
+
if (it != exif_data.end () && (*it).count() == 1) {
num = (double)((*it).toRational(0).first);
den = (double)((*it).toRational(0).second);
-
- if (den == 0)
+
+ if (den == 0) {
+ g_free(altitude_ref);
return FALSE;
-
+ }
+
*altitude = num/den;
- } else
+ } else {
+ g_free(altitude_ref);
return FALSE;
-
+ }
+
if (altitude_ref[0] == '1')
*altitude *= -1.0;
-
+
+ g_free(altitude_ref);
+
return TRUE;
} catch (Exiv2::Error &e) {
LOG_ERROR(e);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]