openbsd-ports/databases/gq/patches/patch-src_util_c

63 lines
1.5 KiB
Plaintext

$OpenBSD: patch-src_util_c,v 1.2 2005/11/12 10:39:08 espie Exp $
--- src/util.c.orig Mon Nov 3 23:28:24 2003
+++ src/util.c Sat Nov 12 04:34:27 2005
@@ -1909,27 +1909,51 @@ GList *get_suffixes(int error_context, s
char **gq_ldap_explode_dn(const char *dn, int dummy)
{
int i, rc;
- LDAPDN *parts;
- char **v = 0;
+ LDAPDN parts;
+ char **v = NULL;
rc = ldap_str2dn(dn, &parts, LDAP_DN_FORMAT_LDAPV3);
- if (rc != LDAP_SUCCESS || parts == NULL) return NULL;
+ if (rc != LDAP_SUCCESS)
+ return NULL;
+ if (parts == NULL) {
+ v = calloc(1, sizeof(char *));
+ if (v == NULL)
+ return NULL;
+ v[0] = NULL;
+ return v;
+ }
/* count DN elements */
for( i = 0 ; parts[i] ; i++ ) ;
- v = (char **) calloc((i + 2), sizeof(char*));
- for( i = 0 ; parts[i] ; i++ ) {
- ldap_rdn2str(parts[0][i], &v[i],
+ v = calloc(i + 1, sizeof(char *));
+ if (v == NULL) {
+ ldap_dnfree(parts);
+ return NULL;
+ }
+
+ for(i = 0; parts[i]; i++) {
+ ldap_rdn2str(parts[i], &v[i],
LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
}
+
+ ldap_dnfree(parts);
+ v[i] = NULL;
+
return v;
}
void gq_exploded_free(char **exploded_dn)
{
- if (exploded_dn) free(exploded_dn);
+ int i;
+
+ if (exploded_dn == NULL)
+ return;
+ for (i = 0; exploded_dn[i]; i++)
+ free(exploded_dn[i]);
+
+ free(exploded_dn);
}
#endif