Bug 89955 - In xdgmime.c pointer is freed before last use
Summary: In xdgmime.c pointer is freed before last use
Status: RESOLVED MOVED
Alias: None
Product: xdgmime
Classification: Unclassified
Component: xdgmime (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Jonathan Blandford
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-08 12:58 UTC by Georgy
Modified: 2018-10-13 10:33 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Georgy 2015-04-08 12:58:55 UTC
In xdgmime.c pointer is freed before last use

See my patch

From: gburanov <georgy.buranov@avira.com>
Date: Wed, 8 Apr 2015 14:51:27 +0200
Subject: [PATCH] fix bug - free data only after use

---
 src/xdgmime.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/xdgmime.c b/src/xdgmime.c
index c7b16bb..032200f 100644
--- a/src/xdgmime.c
+++ b/src/xdgmime.c
@@ -558,13 +558,16 @@ xdg_mime_get_mime_type_for_file (const char  *file_name,
   mime_type = _xdg_mime_magic_lookup_data (global_magic, data, bytes_read, NULL,
 					   mime_types, n);
 
-  free (data);
   fclose (file);
 
-  if (mime_type)
+  if (mime_type) {
+    free (data);
     return mime_type;
+  }
 
-  return _xdg_binary_or_text_fallback(data, bytes_read);
+  mime_type = _xdg_binary_or_text_fallback(data, bytes_read);
+  free (data);
+  return mime_type;
 }
 
 const char *
-- 
1.9.1
Comment 1 GitLab Migration User 2018-10-13 10:33:33 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/xdg/xdgmime/issues/4.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.