]> git.sur5r.net Git - openldap/commitdiff
Plug memory leaks from ldap_get_option().
authorHallvard Furuseth <hallvard@openldap.org>
Wed, 18 Dec 2002 09:37:21 +0000 (09:37 +0000)
committerHallvard Furuseth <hallvard@openldap.org>
Wed, 18 Dec 2002 09:37:21 +0000 (09:37 +0000)
clients/tools/ldapmodify.c

index bb0ee7ffb5f7d7fc8693a9735814bcada1225acf..f00fea1b779594f8174a8d2a72848346465b074c 100644 (file)
@@ -170,7 +170,7 @@ main( int argc, char **argv )
 {
     char               *rbuf, *start, *rejbuf = NULL;
     FILE               *fp, *rejfp;
-       char            *matched_msg = NULL, *error_msg = NULL;
+       char            *matched_msg, *error_msg;
        int             rc, retval;
        int count, len;
 
@@ -253,14 +253,20 @@ main( int argc, char **argv )
        if ( rc && rejfp ) {
                fprintf(rejfp, "# Error: %s (%d)", ldap_err2string(rc), rc);
 
+               matched_msg = NULL;
                ldap_get_option(ld, LDAP_OPT_MATCHED_DN, &matched_msg);
-               if ( matched_msg != NULL && *matched_msg != '\0' ) {
-                       fprintf( rejfp, ", matched DN: %s", matched_msg );
+               if ( matched_msg != NULL ) {
+                       if ( *matched_msg != '\0' )
+                               fprintf( rejfp, ", matched DN: %s", matched_msg );
+                       ldap_memfree( matched_msg );
                }
 
+               error_msg = NULL;
                ldap_get_option(ld, LDAP_OPT_ERROR_STRING, &error_msg);
-               if ( error_msg != NULL && *error_msg != '\0' ) {
-                       fprintf( rejfp, ", additional info: %s", error_msg );
+               if ( error_msg != NULL ) {
+                       if ( *error_msg != '\0' )
+                               fprintf( rejfp, ", additional info: %s", error_msg );
+                       ldap_memfree( error_msg );
                }
                fprintf( rejfp, "\n%s\n", rejbuf );
        }
@@ -548,8 +554,8 @@ end_line:
                         }
                     }
                     pctrls[npc+ndefc] = NULL;
-                    ldap_controls_free(defctrls);  /* Must be freed by library */
                 }
+                ldap_controls_free(defctrls);  /* Must be freed by library */
             }
         }
     }