summaryrefslogtreecommitdiffstats
path: root/src/map.c
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-07-07 19:34:16 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-07-07 19:34:16 -0400
commit540e36f3a050a84ee553425abdad5a3a725a024b (patch)
treeb9971eb74a2d5cd5e7e5c0844e8037327893c1c8 /src/map.c
parent929abb23a0d9468ef95a1076bec8e9b7c7c94f6f (diff)
downloadslapi-nis-540e36f3a050a84ee553425abdad5a3a725a024b.tar.gz
slapi-nis-540e36f3a050a84ee553425abdad5a3a725a024b.tar.xz
slapi-nis-540e36f3a050a84ee553425abdad5a3a725a024b.zip
- free the key length and key tree arrays when we clear a map
Diffstat (limited to 'src/map.c')
-rw-r--r--src/map.c64
1 files changed, 57 insertions, 7 deletions
diff --git a/src/map.c b/src/map.c
index 75d5bc9..c52ce6f 100644
--- a/src/map.c
+++ b/src/map.c
@@ -620,6 +620,7 @@ map_data_clear_map_map(struct plugin_state *state, struct map *map)
/* Clear the entries list. */
if (map != NULL) {
for (entry = map->entries; entry != NULL; entry = next) {
+ next = entry->next;
/* Remove every key for this entry from the applicable
* key trees, and then the ID tree. */
for (i = 0; i < entry->n_keys; i++) {
@@ -629,8 +630,8 @@ map_data_clear_map_map(struct plugin_state *state, struct map *map)
entry->key_index = -1;
}
tdelete(entry, &map->id_tree, t_compare_entry_by_id);
- next = entry->next;
free(entry->id);
+ free(entry->key_len);
entry->key_len = 0;
for (i = 0; i < entry->n_keys; i++) {
free(entry->keys[i]);
@@ -638,10 +639,17 @@ map_data_clear_map_map(struct plugin_state *state, struct map *map)
free(entry->keys);
entry->value_len = 0;
free(entry->value);
+ if ((entry->free_backend_data != NULL) &&
+ (entry->backend_data != NULL)) {
+ entry->free_backend_data(entry->backend_data);
+ }
free(entry);
}
map->entries = NULL;
map->id_tree = NULL;
+ free(map->key_trees);
+ map->key_trees = NULL;
+ map->n_key_trees = 0;
}
}
@@ -674,12 +682,15 @@ map_data_unset_map(struct plugin_state *state,
for (i = 0; i < domain->n_maps; i++) {
if (strcmp(domain->maps[i].name, map_name) == 0) {
map = &domain->maps[i];
- /* Free the contents. */
+ /* Free the individual entries. */
+ map_data_clear_map_map(state, map);
+ /* Free the contents of the map structure itself. */
free(map->name);
- if (map->free_backend_data != NULL) {
+ if ((map->free_backend_data != NULL) &&
+ (map->backend_data != NULL)) {
map->free_backend_data(map->backend_data);
}
- map_data_clear_map_map(state, map);
+ free(map->key_trees);
/* Close the hole in the array. */
domain->n_maps--;
if (i != domain->n_maps) {
@@ -801,7 +812,8 @@ map_data_set_map(struct plugin_state *state,
/* There's already a map there, we just need to update the
* data we're keeping track of for the backend. */
map->secure = secure;
- if (map->free_backend_data != NULL) {
+ if ((map->free_backend_data != NULL) &&
+ (map->backend_data != NULL)) {
map->free_backend_data(map->backend_data);
}
map->backend_data = backend_data;
@@ -845,10 +857,12 @@ map_data_unset_map_entry(struct plugin_state *state,
free(entry->keys[i]);
}
free(entry->keys);
+ free(entry->key_len);
/* The value. */
free(entry->value);
/* Backend data. */
- if (entry->free_backend_data != NULL) {
+ if ((entry->free_backend_data != NULL) &&
+ (entry->backend_data != NULL)) {
entry->free_backend_data(entry->backend_data);
}
/* The entry itself. */
@@ -964,7 +978,8 @@ map_data_set_entry(struct plugin_state *state,
entry->value_len = value_len;
entry->id = strdup(id);
/* Reset the backend data. */
- if (entry->free_backend_data != NULL) {
+ if ((entry->free_backend_data != NULL) &&
+ (entry->backend_data != NULL)) {
entry->free_backend_data(entry->backend_data);
}
entry->backend_data = backend_data;
@@ -1044,6 +1059,41 @@ map_init(struct slapi_pblock *pb, struct plugin_state *state)
return 0;
}
+struct domain_and_map_name {
+ char *domain, *map;
+ struct domain_and_map_name *next;
+};
+static bool_t
+map_get_domain_and_map_name(const char *domain, const char *map, bool_t flag,
+ void *backend_data, void *cbdata)
+{
+ struct domain_and_map_name **names, *this_one;
+ this_one = malloc(sizeof(*this_one));
+ if (this_one != NULL) {
+ this_one->domain = strdup(domain);
+ this_one->map = strdup(map);
+ names = cbdata;
+ this_one->next = *names;
+ *names = this_one;
+ }
+ return TRUE;
+}
+void
+map_done(struct plugin_state *state)
+{
+ struct domain_and_map_name *names, *next;
+ names = NULL;
+ map_data_foreach_map(state, NULL, map_get_domain_and_map_name, &names);
+ while (names != NULL) {
+ next = names->next;
+ map_data_clear_map(state, names->domain, names->map);
+ free(names->domain);
+ free(names->map);
+ free(names);
+ names = next;
+ }
+}
+
void
map_rdlock(void)
{