Changeset 3020

Show
Ignore:
Timestamp:
11/10/08 22:28:10 (2 months ago)
Author:
nashif
Message:

Fixed potential memory leak (bug 273)

In file uri.c, method u_parse_query() mallocs memory for key and val
character pointers but this is never free'd in cases where string unify
operations fail, hash insertions fail or when there is already a
duplicate entry present in the hash.

The following is the proposed patch to fix the bug:

Index: src/lib/u/uri.c
===================================================================
--- src/lib/u/uri.c (revision 3016)
+++ src/lib/u/uri.c (working copy)
@@ -227,14 +227,19 @@

u_trim_quotes(val);

if (u_string_unify(key) u_string_unify(val)) {

u_free(key);

+ u_free(val);

dbg("Could not unify query: %s", tok);
continue;

}
if (!hash_lookup(h, key)) {

if (!hash_alloc_insert(h, key, val)) {

+ u_free(key);
+ u_free(val);

warn("hash_alloc_insert failed");

}

} else {

+ u_free(key);
+ u_free(val);

warn("duplicate not added to hash");

}

}

--
Suresh Sundriyal

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openwsman/trunk/src/lib/u/uri.c

    r2779 r3020  
    228228                if (u_string_unify(key) || u_string_unify(val)) { 
    229229                        u_free(key); 
     230                        u_free(val); 
    230231                        dbg("Could not unify query: %s", tok); 
    231232                        continue; 
     
    233234                if (!hash_lookup(h, key)) { 
    234235                        if (!hash_alloc_insert(h, key, val)) { 
     236                                u_free(key); 
     237                                u_free(val); 
    235238                                warn("hash_alloc_insert failed"); 
    236239                        } 
    237240                } else { 
     241                        u_free(key); 
     242                        u_free(val); 
    238243                        warn("duplicate not added to hash"); 
    239244                }