[389-devel] Please review: fix memory leak in attr replace when replacement fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




>From 7be88811a1b26a4cac6cb0e25386c795f72dabef Mon Sep 17 00:00:00 2001
From: Rich Megginson <rmeggins@xxxxxxxxxx>
Date: Wed, 24 Feb 2010 09:48:36 -0700
Subject: [PATCH] fix memory leak in attr replace when replacement fails

if replacement of the attribute values fails (e.g. due to duplicate values)
the valstoreplace is not freed - the caller expects the valueset_replace
function to own the values passed in.  The function will now free the values
if there was an error
In addition, valueset_replace should not free the old values in case
of error - it should leave the old values in the attribute
---
 ldap/servers/slapd/valueset.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/ldap/servers/slapd/valueset.c b/ldap/servers/slapd/valueset.c
index a9cd37e..d6909ac 100644
--- a/ldap/servers/slapd/valueset.c
+++ b/ldap/servers/slapd/valueset.c
@@ -1345,10 +1345,6 @@ valueset_replace(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **valstoreplace)
 {
     int rc = LDAP_SUCCESS;
     int numberofvalstoreplace= valuearray_count(valstoreplace);
-    if(!valuearray_isempty(vs->va))
-    {
-        slapi_valueset_done(vs);
-    }
     /* verify the given values are not duplicated.
        if replacing with one value, no need to check.  just replace it.
      */
@@ -1368,8 +1364,21 @@ valueset_replace(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **valstoreplace)
 
     if ( rc == LDAP_SUCCESS )
     {
+        /* values look good - replace the values in the attribute */
+        if(!valuearray_isempty(vs->va))
+        {
+            /* remove old values */
+            slapi_valueset_done(vs);
+        }
+        /* we now own valstoreplace */
         vs->va = valstoreplace;
     }
+    else
+    {
+        /* caller expects us to own valstoreplace - since we cannot
+           use them, just delete them */
+        valuearray_free(&valstoreplace);
+    }
     return rc;
 }
 
-- 
1.5.5.6

--
389-devel mailing list
389-devel@xxxxxxxxxxxxxxxxxxxxxxx
https://admin.fedoraproject.org/mailman/listinfo/389-devel

[Index of Archives]     [Fedora Directory Announce]     [Fedora Users]     [Older Fedora Users Mail]     [Fedora Advisory Board]     [Fedora Security]     [Fedora Devel Java]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Mentors]     [Fedora Package Review]     [Fedora Art]     [Fedora Music]     [Fedora Packaging]     [CentOS]     [Fedora SELinux]     [Big List of Linux Books]     [KDE Users]     [Fedora Art]     [Fedora Docs]

  Powered by Linux