Author: sandervanderburg
Date: Wed Nov  3 16:49:05 2010
New Revision: 24585
URL: https://svn.nixos.org/websvn/nix/?rev=24585&sc=1

Log:
- Fixed some wild pointers that may occur while parsing an incorrect XML file
- Some small code cleanups & typo fixes

Modified:
   disnix/disnix/trunk/src/libdistderivation/derivationmapping.c
   disnix/disnix/trunk/src/libmanifest/activationmapping.c
   disnix/disnix/trunk/src/libmanifest/distributionmapping.c

Modified: disnix/disnix/trunk/src/libdistderivation/derivationmapping.c
==============================================================================
--- disnix/disnix/trunk/src/libdistderivation/derivationmapping.c       Wed Nov 
 3 14:03:53 2010        (r24584)
+++ disnix/disnix/trunk/src/libdistderivation/derivationmapping.c       Wed Nov 
 3 16:49:05 2010        (r24585)
@@ -27,7 +27,6 @@
     xmlNodePtr node_root;
     xmlXPathObjectPtr result;
     GArray *derivation_array = NULL;
-    unsigned int i;
     
     /* Parse the XML document */
     
@@ -57,6 +56,7 @@
     if(result)
     {
        xmlNodeSetPtr nodeset = result->nodesetval;
+       unsigned int i;
        
        /* Create a derivation array */
         derivation_array = g_array_new(FALSE, FALSE, sizeof(DerivationItem*));
@@ -66,7 +66,7 @@
         {
            xmlNodePtr mapping_children = nodeset->nodeTab[i]->children;
            DerivationItem *item = 
(DerivationItem*)g_malloc(sizeof(DerivationItem));
-           gchar *derivation, *target;
+           gchar *derivation = NULL, *target = NULL;
            
            /* Iterate over all the mapping item children (derivation and 
target elements) */
            

Modified: disnix/disnix/trunk/src/libmanifest/activationmapping.c
==============================================================================
--- disnix/disnix/trunk/src/libmanifest/activationmapping.c     Wed Nov  3 
14:03:53 2010        (r24584)
+++ disnix/disnix/trunk/src/libmanifest/activationmapping.c     Wed Nov  3 
16:49:05 2010        (r24585)
@@ -137,7 +137,6 @@
     xmlNodePtr node_root;
     xmlXPathObjectPtr result;
     GArray *activation_array;
-    unsigned int i;
     
     /* Parse the XML document */
     
@@ -170,15 +169,16 @@
     if(result)
     {
        xmlNodeSetPtr nodeset = result->nodesetval;
-               
+       unsigned int i;
+       
        /* Iterate over all the mapping elements */
        for(i = 0; i < nodeset->nodeNr; i++)
         {
            xmlNodePtr mapping_children = nodeset->nodeTab[i]->children;
-           gchar *service;
-           GArray *target;
-           gchar *targetProperty;
-           gchar *type;
+           gchar *service = NULL;
+           GArray *target = NULL;
+           gchar *targetProperty = NULL;
+           gchar *type = NULL;
            GArray *depends_on = NULL;
            ActivationMapping *mapping = 
(ActivationMapping*)g_malloc(sizeof(ActivationMapping));
            
@@ -299,17 +299,20 @@
 
 static void delete_target_array(GArray *target)
 {
-    unsigned int i;
-    
-    for(i = 0; i < target->len; i++)
+    if(target != NULL)
     {
-        TargetProperty *target_property = g_array_index(target, 
TargetProperty*, i);
-        g_free(target_property->name);
-        g_free(target_property->value);
-        g_free(target_property);
-    }
+       unsigned int i;
+    
+       for(i = 0; i < target->len; i++)
+       {
+           TargetProperty *target_property = g_array_index(target, 
TargetProperty*, i);
+           g_free(target_property->name);
+           g_free(target_property->value);
+           g_free(target_property);
+       }
        
-    g_array_free(target, TRUE);
+       g_array_free(target, TRUE);
+    }
 }
 
 void delete_activation_array(GArray *activation_array)
@@ -322,16 +325,19 @@
        unsigned int j;
        
        g_free(mapping->service);
-       delete_target_array(mapping->target);   
+       delete_target_array(mapping->target);
        g_free(mapping->targetProperty);
        g_free(mapping->type);
        
-       for(j = 0; j < mapping->depends_on->len; j++)
+       if(mapping->depends_on != NULL)
        {
-           Dependency *dependency = g_array_index(mapping->depends_on, 
Dependency*, j);
-           g_free(dependency->service);
-           delete_target_array(dependency->target);
-           g_free(dependency);
+           for(j = 0; j < mapping->depends_on->len; j++)
+           {
+               Dependency *dependency = g_array_index(mapping->depends_on, 
Dependency*, j);
+               g_free(dependency->service);
+               delete_target_array(dependency->target);
+               g_free(dependency);
+           }
        }
        
        g_array_free(mapping->depends_on, TRUE);
@@ -405,7 +411,6 @@
 GArray *substract_activation_array(GArray *left, GArray *right)
 {
     unsigned int i;
-    
     GArray *return_array = g_array_new(FALSE, FALSE, 
sizeof(ActivationMapping*));
     
     /* Create a clone of the left array */

Modified: disnix/disnix/trunk/src/libmanifest/distributionmapping.c
==============================================================================
--- disnix/disnix/trunk/src/libmanifest/distributionmapping.c   Wed Nov  3 
14:03:53 2010        (r24584)
+++ disnix/disnix/trunk/src/libmanifest/distributionmapping.c   Wed Nov  3 
16:49:05 2010        (r24585)
@@ -27,7 +27,6 @@
     xmlNodePtr node_root;
     xmlXPathObjectPtr result;
     GArray *distribution_array = NULL;
-    unsigned int i;
     
     /* Parse the XML document */
     
@@ -56,6 +55,7 @@
     
     if(result)
     {
+       unsigned int i;
        xmlNodeSetPtr nodeset = result->nodesetval;
        
        /* Create a distribution array */
@@ -66,7 +66,7 @@
         {
            xmlNodePtr mapping_children = nodeset->nodeTab[i]->children;
            DistributionItem *item = 
(DistributionItem*)g_malloc(sizeof(DistributionItem));
-           gchar *profile, *target;
+           gchar *profile = NULL, *target = NULL;
            
            /* Iterate over all the mapping item children (profile and target 
elements) */
            
@@ -80,7 +80,7 @@
                mapping_children = mapping_children->next;
            }
            
-           /* Added the mapping to the array */
+           /* Add the mapping to the array */
            item->profile = profile;
            item->target = target;
            g_array_append_val(distribution_array, item);
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits

Reply via email to