From: Jean Delvare <khali@linux-fr.org>
Subject: Fix memory allocation and freeing in add_sensor_tab

* When realloc fails, it doesn't free the original buffer.
* strcat never fails.
* Use free, not g_free, to free memory not allocated with g_malloc.
* No need to free feattext twice.
---
 src/gui.c |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

--- a/src/gui.c
+++ b/src/gui.c
@@ -358,19 +358,20 @@
             feattext = sensors_get_label( name, feature );
 	    
             if ( feattext != NULL ) {
+                /* We need a temporary variable in case realloc fails */
+                char *new_feattext;
 #ifdef DEBUG_XSENSORS
                 printf( "Adding feature %d, %s.\n", i, feattext );
 #endif
-                if ( ( feattext = realloc( feattext, 
+                if ( ( new_feattext = realloc( feattext,
                                 ( strlen( feattext ) + 2 ) * 
                                 sizeof( char ) ) ) == NULL ) {
                     fprintf( stderr, "realloc failed in add_sensor_tab()!\n" );
+                    free( feattext );
                     return NULL;
                 }
-                if ( strcat( feattext, ":" ) == NULL ) {
-                    fprintf( stderr, "strcat failed in add_sensor_tab()!\n" );
-                    return NULL;
-                }
+                feattext = new_feattext;
+                strcat( feattext, ":" );
                 
                 gtk_frame_set_label( GTK_FRAME (featframe), feattext );
 
@@ -408,8 +409,7 @@
             gtk_widget_show( innerbox );
             gtk_widget_show( darea );
             gtk_widget_show( featpbar );
-            g_free( feattext );
-            feattext = NULL;
+            free( feattext );
     }
 
     if ( usedvolt > 0 ) {
@@ -430,8 +430,6 @@
         gtk_widget_show( fanlabel );
     }
 
-    g_free( feattext );
-
     return head;
 }
 
