packet-radius.c, packet-xml.c:
authorjmayer <jmayer@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 20 Dec 2005 08:35:53 +0000 (08:35 +0000)
committerjmayer <jmayer@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 20 Dec 2005 08:35:53 +0000 (08:35 +0000)
        Fix a memory leak found by valgrind:
        Although dir isn't a directory it may still use memory

packet-xml.c:
        Reformat the relevant function in packet-xml.c to be readable on systems
        where a tab is 8 spaces.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@16865 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dissectors/packet-radius.c
epan/dissectors/packet-xml.c

index 59591b78264011b76cfeb03d7efb82e701e7ffc0..5ae221eadb473648e98dd6511126afb7d42a3ced 100644 (file)
@@ -1101,6 +1101,8 @@ proto_register_radius(void)
        dir = get_persconffile_path("radius", FALSE);
        
        if (test_for_directory(dir) != EISDIR) {
+               /* Although dir isn't a directory it may still use memory */
+               g_free(dir);
                
                dir = get_datafile_path("radius");
                
index 4c4bb0043cb8ad2a89d576a66150e73878725ade..b41f6793d73fe856c1f8c3b76b207522ae46f4e0 100644 (file)
@@ -1061,16 +1061,16 @@ next_attribute:
 static void init_xml_names(void) {
        xml_ns_t* xmlpi_xml_ns;
        guint i;
-    DIRECTORY_T* dir;
-    const FILE_T* file;
-    const gchar* filename;
-    gchar* dirname;
-    
+       DIRECTORY_T* dir;
+       const FILE_T* file;
+       const gchar* filename;
+       gchar* dirname;
+       
 #if GLIB_MAJOR_VERSION >= 2
-    GError** dummy = g_malloc(sizeof(GError *));
-    *dummy = NULL;
+       GError** dummy = g_malloc(sizeof(GError *));
+       *dummy = NULL;
 #endif
-    
+       
        xmpli_names = g_hash_table_new(g_str_hash,g_str_equal);
        media_types = g_hash_table_new(g_str_hash,g_str_equal);
        
@@ -1082,55 +1082,57 @@ static void init_xml_names(void) {
        g_hash_table_destroy(xmlpi_xml_ns->elements);
        xmlpi_xml_ns->elements = NULL;
 
-    
-    dirname = get_persconffile_path("dtds", FALSE);
+       
+       dirname = get_persconffile_path("dtds", FALSE);
        
        if (test_for_directory(dirname) != EISDIR) {
+               /* Although dir isn't a directory it may still use memory */
+               g_free(dirname);
                dirname = get_datafile_path("dtds");
-    }
-    
+       }
+       
        if (test_for_directory(dirname) == EISDIR) {
-        
-        if ((dir = OPENDIR_OP(dirname)) != NULL) {
-            while ((file = DIRGETNEXT_OP(dir)) != NULL) {
-                guint namelen;
-                filename = GETFNAME_OP(file);
-                
-                namelen = strlen(filename);
-                if ( namelen > 4 && ( g_strcasecmp(filename+(namelen-4),".dtd")  == 0 ) ) {
-                    GString* errors = g_string_new("");
-                    GString* preparsed = dtd_preparse(dirname, filename, errors);
-                    dtd_build_data_t* dtd_data;
-                    
-                    if (errors->len) {
-                        report_failure("Dtd Preparser in file %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,errors->str);
-                        continue;
-                    }
-                    
-                    dtd_data = dtd_parse(preparsed);
-                    
-                    g_string_free(preparsed,TRUE);
-                    
-                    if (dtd_data->error->len) {
-                        report_failure("Dtd Parser in file %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,dtd_data->error->str);
-                        destroy_dtd_data(dtd_data);
-                        continue;
-                    }
-                    
-                    register_dtd(dtd_data,errors);
-                    
-                    if (errors->len) {
-                        report_failure("Dtd Registration in file: %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,errors->str);
-                        g_string_free(errors,TRUE);
-                        continue;
-                    }
-                }
-            }
-            
-            CLOSEDIR_OP(dir);
-        }
-    }
-    
+           
+           if ((dir = OPENDIR_OP(dirname)) != NULL) {
+               while ((file = DIRGETNEXT_OP(dir)) != NULL) {
+                   guint namelen;
+                   filename = GETFNAME_OP(file);
+                   
+                   namelen = strlen(filename);
+                   if ( namelen > 4 && ( g_strcasecmp(filename+(namelen-4),".dtd")  == 0 ) ) {
+                       GString* errors = g_string_new("");
+                       GString* preparsed = dtd_preparse(dirname, filename, errors);
+                       dtd_build_data_t* dtd_data;
+                       
+                       if (errors->len) {
+                           report_failure("Dtd Preparser in file %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,errors->str);
+                           continue;
+                       }
+                       
+                       dtd_data = dtd_parse(preparsed);
+                       
+                       g_string_free(preparsed,TRUE);
+                       
+                       if (dtd_data->error->len) {
+                           report_failure("Dtd Parser in file %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,dtd_data->error->str);
+                           destroy_dtd_data(dtd_data);
+                           continue;
+                       }
+                       
+                       register_dtd(dtd_data,errors);
+                       
+                       if (errors->len) {
+                           report_failure("Dtd Registration in file: %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,errors->str);
+                           g_string_free(errors,TRUE);
+                           continue;
+                       }
+                   }
+               }
+               
+               CLOSEDIR_OP(dir);
+           }
+       }
+       
        for(i=0;i<array_length(default_media_types);i++) {
                if( ! g_hash_table_lookup(media_types,default_media_types[i]) ) {
                        g_hash_table_insert(media_types,(gpointer)default_media_types[i],&xml_ns);
@@ -1140,7 +1142,7 @@ static void init_xml_names(void) {
        g_hash_table_foreach(xmpli_names,add_xmlpi_namespace,"xml.xmlpi");
 
 #if GLIB_MAJOR_VERSION >= 2
-    g_free(dummy);
+       g_free(dummy);
 #endif    
 }