* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: rdataset.c,v 1.70 2004/01/14 02:06:50 marka Exp $ */
+/* $Id: rdataset.c,v 1.71 2004/02/19 01:23:42 marka Exp $ */
#include <config.h>
#include <stdlib.h>
#include <isc/buffer.h>
+#include <isc/mem.h>
#include <isc/random.h>
#include <isc/util.h>
unsigned int headlen;
isc_boolean_t question = ISC_FALSE;
isc_boolean_t shuffle = ISC_FALSE;
- dns_rdata_t shuffled[MAX_SHUFFLE];
- struct towire_sort sorted[MAX_SHUFFLE];
+ dns_rdata_t *shuffled = NULL, shuffled_fixed[MAX_SHUFFLE];
+ struct towire_sort *sorted = NULL, sorted_fixed[MAX_SHUFFLE];
UNUSED(state);
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(countp != NULL);
REQUIRE((order == NULL) == (order_arg == NULL));
+ REQUIRE(cctx != NULL && cctx->mctx != NULL);
count = 0;
if ((rdataset->attributes & DNS_RDATASETATTR_QUESTION) != 0) {
}
/*
- * We'll only shuffle if we've got enough slots in our
- * deck.
- *
- * There's no point to shuffling SIGs.
+ * Do we want to shuffle this anwer?
*/
- if (!question &&
- count > 1 &&
+ if (!question && count > 1 &&
(!WANT_FIXED(rdataset) || order != NULL) &&
- count <= MAX_SHUFFLE &&
rdataset->type != dns_rdatatype_rrsig)
- {
shuffle = ISC_TRUE;
+
+ if (shuffle && count > MAX_SHUFFLE) {
+ shuffled = isc_mem_get(cctx->mctx, count * sizeof(*shuffled));
+ sorted = isc_mem_get(cctx->mctx, count * sizeof(*sorted));
+ if (shuffled == NULL || sorted == NULL)
+ shuffle = ISC_FALSE;
+ } else {
+ shuffled = shuffled_fixed;
+ sorted = sorted_fixed;
+ }
+
+ if (shuffle) {
/*
* First we get handles to all of the rdata.
*/
result = dns_rdataset_next(rdataset);
} while (result == ISC_R_SUCCESS);
if (result != ISC_R_NOMORE)
- return (result);
+ goto cleanup;
INSIST(i == count);
/*
*countp += count;
- return (ISC_R_SUCCESS);
+ result = ISC_R_SUCCESS;
+ goto cleanup;
rollback:
if (partial && result == ISC_R_NOSPACE) {
dns_compress_rollback(cctx, (isc_uint16_t)rrbuffer.used);
*countp += added;
*target = rrbuffer;
- return (result);
+ goto cleanup;
}
INSIST(savedbuffer.used < 65536);
dns_compress_rollback(cctx, (isc_uint16_t)savedbuffer.used);
*countp = 0;
*target = savedbuffer;
+ cleanup:
+ if (sorted != NULL && sorted != sorted_fixed)
+ isc_mem_put(cctx->mctx, sorted, count * sizeof(*sorted));
+ if (shuffled != NULL && shuffled != shuffled_fixed)
+ isc_mem_put(cctx->mctx, shuffled, count * sizeof(*shuffled));
return (result);
}