[geany/geany] 6e46cc: Fix mismatching allocation and deallocation

Colomban Wendling git-noreply at xxxxx
Sun Nov 3 00:52:27 UTC 2013


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sun, 03 Nov 2013 00:52:27 UTC
Commit:      6e46cca735fc4ab19c629f5a2d47aad2180cb302
             https://github.com/geany/geany/commit/6e46cca735fc4ab19c629f5a2d47aad2180cb302

Log Message:
-----------
Fix mismatching allocation and deallocation

When allocation with g_malloc(), the memory should be freed using
g_free(), not plain free().

Also, use g_try_malloc() instead of g_malloc() where the code carefully
handles allocation failures itself.


Modified Paths:
--------------
    tagmanager/ctags/sort.c

Modified: tagmanager/ctags/sort.c
10 files changed, 5 insertions(+), 5 deletions(-)
===================================================================
@@ -65,7 +65,7 @@ extern void externalSortTags (const boolean toStdout)
     PE_CONST char *const sortOrder2 = "LC_ALL=C";
     const size_t length	= 4 + strlen (sortOrder1) + strlen (sortOrder2) +
 	    strlen (sortCommand) + (2 * strlen (tagFileName ()));
-    char *const cmd = (char *) g_malloc (length + 1);
+    char *const cmd = (char *) g_try_malloc (length + 1);
     int ret = -1;
 
     if (cmd != NULL)
@@ -165,7 +165,7 @@ extern void internalSortTags (const boolean toStdout)
      */
     size_t numTags = TagFile.numTags.added + TagFile.numTags.prev;
     const size_t tableSize = numTags * sizeof (char *);
-    char **const table = (char **) g_malloc (tableSize);	/* line pointers */
+    char **const table = (char **) g_try_malloc (tableSize);	/* line pointers */
     DebugStatement ( size_t mallocSize = tableSize; )	/* cumulative total */
 
     if (table == NULL)
@@ -191,7 +191,7 @@ extern void internalSortTags (const boolean toStdout)
 	{
 	    const size_t stringSize = strlen (line) + 1;
 
-	    table [i] = (char *) g_malloc (stringSize);
+	    table [i] = (char *) g_try_malloc (stringSize);
 	    if (table [i] == NULL)
 		failedSort (mio, "out of memory");
 	    DebugStatement ( mallocSize += stringSize; )
@@ -211,8 +211,8 @@ extern void internalSortTags (const boolean toStdout)
 
     PrintStatus (("sort memory: %ld bytes\n", (long) mallocSize));
     for (i = 0 ; i < numTags ; ++i)
-	free (table [i]);
-    free (table);
+	g_free (table [i]);
+    g_free (table);
 }
 
 #endif



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list