Browse Source

Avoid freeing NULL trimmed passwords list

My previous patch for removing the fixed length buffer used in
the password history checking code introduced a problem where we
could attempt to free a NULL pointer.
Nathan Kinder 16 years ago
parent
commit
5c71f20ebf
1 changed files with 9 additions and 9 deletions
  1. 9 9
      ldap/servers/slapd/pw.c

+ 9 - 9
ldap/servers/slapd/pw.c

@@ -1120,7 +1120,7 @@ int update_pw_history( Slapi_PBlock *pb, char *dn, char *old_pw ) {
 static
 int pw_in_history( Slapi_Value **history_vals, const Slapi_Value *pw_val)
 {
-	Slapi_Value **trimmed_history;
+	Slapi_Value **trimmed_history = NULL;
 	int num_history_vals = 0;
 	int i;
 	int	ret = -1;
@@ -1183,16 +1183,16 @@ int pw_in_history( Slapi_Value **history_vals, const Slapi_Value *pw_val)
 
 		/* Check if the new password is in the trimmed history list. */
 		ret = slapi_pw_find_sv(trimmed_history, pw_val);
-	}
 	
-	/* Free the trimmed values. */
-	for ( i = 0; trimmed_history[i] != NULL; i++ )
-	{
-		slapi_ch_free((void **)&trimmed_history[i]);
-	}
+		/* Free the trimmed values. */
+		for ( i = 0; trimmed_history[i] != NULL; i++ )
+		{
+			slapi_ch_free((void **)&trimmed_history[i]);
+		}
 
-	/* Free the array. */
-	slapi_ch_free((void **)&trimmed_history);
+		/* Free the array. */
+		slapi_ch_free((void **)&trimmed_history);
+	}
 
 	return ( ret );
 }