[gnome-builder] clang: plug GFile/IdeFile leak



commit f7e18ba1be6a5a6c8023432b2e1d620de5db45e7
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jan 13 02:17:09 2018 -0800

    clang: plug GFile/IdeFile leak

 src/plugins/clang/ide-clang-translation-unit.c | 60 ++++++++------------------
 1 file changed, 18 insertions(+), 42 deletions(-)
---
diff --git a/src/plugins/clang/ide-clang-translation-unit.c b/src/plugins/clang/ide-clang-translation-unit.c
index f0324ddbf..2111501e6 100644
--- a/src/plugins/clang/ide-clang-translation-unit.c
+++ b/src/plugins/clang/ide-clang-translation-unit.c
@@ -199,16 +199,12 @@ static gchar *
 get_path (const gchar *workpath,
           const gchar *path)
 {
-  if (g_str_has_prefix (path, workpath))
-    {
-      path = path + strlen (workpath);
-      while (*path == G_DIR_SEPARATOR)
-        path++;
-
-      return g_strdup (path);
-    }
-
-  return g_strdup (path);
+  if (path == NULL)
+    return g_strdup (workpath);
+  else if (g_str_has_prefix (path, workpath))
+    return g_strdup (path);
+  else
+    return g_build_filename (workpath, path, NULL);
 }
 
 static IdeSourceLocation *
@@ -217,18 +213,18 @@ create_location (IdeClangTranslationUnit *self,
                  const gchar             *workpath,
                  CXSourceLocation         cxloc)
 {
-  IdeSourceLocation *ret = NULL;
-  IdeFile *file = NULL;
-  CXFile cxfile = NULL;
   g_autofree gchar *path = NULL;
-  const gchar *cstr;
-  CXString str;
+  g_autoptr(IdeFile) file = NULL;
+  g_autoptr(GFile) gfile = NULL;
+  g_auto(CXString) str = {0};
+  IdeContext *context;
+  CXFile cxfile = NULL;
   unsigned line;
   unsigned column;
   unsigned offset;
 
-  g_return_val_if_fail (self, NULL);
-  g_return_val_if_fail (workpath, NULL);
+  g_return_val_if_fail (self != NULL, NULL);
+  g_return_val_if_fail (workpath != NULL, NULL);
 
   clang_getFileLocation (cxloc, &cxfile, &line, &column, &offset);
 
@@ -236,33 +232,13 @@ create_location (IdeClangTranslationUnit *self,
   if (column > 0) column--;
 
   str = clang_getFileName (cxfile);
-  cstr = clang_getCString (str);
-  if (cstr != NULL)
-    path = get_path (workpath, cstr);
-  clang_disposeString (str);
-  if (cstr == NULL)
-    return NULL;
-
-  file = ide_project_get_file_for_path (project, path);
+  path = get_path (workpath, clang_getCString (str));
 
-  if (!file)
-    {
-      IdeContext *context;
-      GFile *gfile;
-
-      context = ide_object_get_context (IDE_OBJECT (self));
-      gfile = g_file_new_for_path (path);
-
-      file = g_object_new (IDE_TYPE_FILE,
-                           "context", context,
-                           "file", gfile,
-                           "path", path,
-                           NULL);
-    }
-
-  ret = ide_source_location_new (file, line, column, offset);
+  context = ide_object_get_context (IDE_OBJECT (self));
+  gfile = g_file_new_for_path (path);
+  file = ide_file_new (context, gfile);
 
-  return ret;
+  return ide_source_location_new (file, line, column, offset);
 }
 
 static IdeSourceRange *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]