SF.net SVN: geany-plugins:[2065] trunk/geany-plugins/treebrowser/src/ treebrowser.c
colombanw at users.sourceforge.net
colombanw at xxxxx
Thu May 12 20:55:12 UTC 2011
Revision: 2065
http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2065&view=rev
Author: colombanw
Date: 2011-05-12 20:55:11 +0000 (Thu, 12 May 2011)
Log Message:
-----------
TreeBrowser: Fix crash and memory leak in treebrowser.c.
In path_is_in_dir(), if it's about to return NULL (if the function parameters
have no path components in common) it tried to free() a string
literal, which causes a crash. In the same function, there was a memory leak,
because diffed_path was reassigned without being free()'d before.
Fix both problems.
Patch by Thomas Martitz, thanks.
Modified Paths:
--------------
trunk/geany-plugins/treebrowser/src/treebrowser.c
Modified: trunk/geany-plugins/treebrowser/src/treebrowser.c
===================================================================
--- trunk/geany-plugins/treebrowser/src/treebrowser.c 2011-05-10 02:15:23 UTC (rev 2064)
+++ trunk/geany-plugins/treebrowser/src/treebrowser.c 2011-05-12 20:55:11 UTC (rev 2065)
@@ -222,13 +222,15 @@
#endif
}
+
+/* result must be freed */
static gchar*
path_is_in_dir(gchar* src, gchar* find)
{
int i = 0;
gboolean found = FALSE;
- gchar *diffed_path = "", *tmp = NULL;
+ gchar *diffed_path = NULL, *tmp = NULL;
gchar **src_segments = NULL, **find_segments = NULL;
guint src_segments_n = 0, find_segments_n = 0, n = 0;
@@ -247,7 +249,9 @@
break;
else
{
- tmp = g_strconcat(diffed_path, G_DIR_SEPARATOR_S, find_segments[i], NULL);
+ tmp = g_strconcat(diffed_path == NULL ? "" : diffed_path,
+ G_DIR_SEPARATOR_S, find_segments[i], NULL);
+ g_free(diffed_path);
diffed_path = g_strdup(tmp);
g_free(tmp);
found = TRUE;
@@ -258,7 +262,6 @@
if (found)
return diffed_path;
- g_free(diffed_path);
return NULL;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Plugins-Commits
mailing list