]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - contrib/bind9/lib/dns/diff.c
MFC r362623:
[FreeBSD/stable/8.git] / contrib / bind9 / lib / dns / diff.c
1 /*
2  * Copyright (C) 2004, 2005, 2007-2009, 2011-2014  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000-2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id$ */
19
20 /*! \file */
21
22 #include <config.h>
23
24 #include <stdlib.h>
25
26 #include <isc/buffer.h>
27 #include <isc/file.h>
28 #include <isc/mem.h>
29 #include <isc/string.h>
30 #include <isc/util.h>
31
32 #include <dns/db.h>
33 #include <dns/diff.h>
34 #include <dns/log.h>
35 #include <dns/rdataclass.h>
36 #include <dns/rdatalist.h>
37 #include <dns/rdataset.h>
38 #include <dns/rdatastruct.h>
39 #include <dns/rdatatype.h>
40 #include <dns/result.h>
41
42 #define CHECK(op) \
43         do { result = (op);                                     \
44                 if (result != ISC_R_SUCCESS) goto failure;      \
45         } while (0)
46
47 #define DIFF_COMMON_LOGARGS \
48         dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DIFF
49
50 static dns_rdatatype_t
51 rdata_covers(dns_rdata_t *rdata) {
52         return (rdata->type == dns_rdatatype_rrsig ?
53                 dns_rdata_covers(rdata) : 0);
54 }
55
56 isc_result_t
57 dns_difftuple_create(isc_mem_t *mctx,
58                      dns_diffop_t op, dns_name_t *name, dns_ttl_t ttl,
59                      dns_rdata_t *rdata, dns_difftuple_t **tp)
60 {
61         dns_difftuple_t *t;
62         unsigned int size;
63         unsigned char *datap;
64
65         REQUIRE(tp != NULL && *tp == NULL);
66
67         /*
68          * Create a new tuple.  The variable-size wire-format name data and
69          * rdata immediately follow the dns_difftuple_t structure
70          * in memory.
71          */
72         size = sizeof(*t) + name->length + rdata->length;
73         t = isc_mem_allocate(mctx, size);
74         if (t == NULL)
75                 return (ISC_R_NOMEMORY);
76         t->mctx = mctx;
77         t->op = op;
78
79         datap = (unsigned char *)(t + 1);
80
81         memmove(datap, name->ndata, name->length);
82         dns_name_init(&t->name, NULL);
83         dns_name_clone(name, &t->name);
84         t->name.ndata = datap;
85         datap += name->length;
86
87         t->ttl = ttl;
88
89         memmove(datap, rdata->data, rdata->length);
90         dns_rdata_init(&t->rdata);
91         dns_rdata_clone(rdata, &t->rdata);
92         t->rdata.data = datap;
93         datap += rdata->length;
94
95         ISC_LINK_INIT(&t->rdata, link);
96         ISC_LINK_INIT(t, link);
97         t->magic = DNS_DIFFTUPLE_MAGIC;
98
99         INSIST(datap == (unsigned char *)t + size);
100
101         *tp = t;
102         return (ISC_R_SUCCESS);
103 }
104
105 void
106 dns_difftuple_free(dns_difftuple_t **tp) {
107         dns_difftuple_t *t = *tp;
108         REQUIRE(DNS_DIFFTUPLE_VALID(t));
109         dns_name_invalidate(&t->name);
110         t->magic = 0;
111         isc_mem_free(t->mctx, t);
112         *tp = NULL;
113 }
114
115 isc_result_t
116 dns_difftuple_copy(dns_difftuple_t *orig, dns_difftuple_t **copyp) {
117         return (dns_difftuple_create(orig->mctx, orig->op, &orig->name,
118                                      orig->ttl, &orig->rdata, copyp));
119 }
120
121 void
122 dns_diff_init(isc_mem_t *mctx, dns_diff_t *diff) {
123         diff->mctx = mctx;
124         diff->resign = 0;
125         ISC_LIST_INIT(diff->tuples);
126         diff->magic = DNS_DIFF_MAGIC;
127 }
128
129 void
130 dns_diff_clear(dns_diff_t *diff) {
131         dns_difftuple_t *t;
132         REQUIRE(DNS_DIFF_VALID(diff));
133         while ((t = ISC_LIST_HEAD(diff->tuples)) != NULL) {
134                 ISC_LIST_UNLINK(diff->tuples, t, link);
135                 dns_difftuple_free(&t);
136         }
137         ENSURE(ISC_LIST_EMPTY(diff->tuples));
138 }
139
140 void
141 dns_diff_append(dns_diff_t *diff, dns_difftuple_t **tuplep)
142 {
143         ISC_LIST_APPEND(diff->tuples, *tuplep, link);
144         *tuplep = NULL;
145 }
146
147 /* XXX this is O(N) */
148
149 void
150 dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuplep)
151 {
152         dns_difftuple_t *ot, *next_ot;
153
154         REQUIRE(DNS_DIFF_VALID(diff));
155         REQUIRE(DNS_DIFFTUPLE_VALID(*tuplep));
156
157         /*
158          * Look for an existing tuple with the same owner name,
159          * rdata, and TTL.   If we are doing an addition and find a
160          * deletion or vice versa, remove both the old and the
161          * new tuple since they cancel each other out (assuming
162          * that we never delete nonexistent data or add existing
163          * data).
164          *
165          * If we find an old update of the same kind as
166          * the one we are doing, there must be a programming
167          * error.  We report it but try to continue anyway.
168          */
169         for (ot = ISC_LIST_HEAD(diff->tuples); ot != NULL;
170              ot = next_ot)
171         {
172                 next_ot = ISC_LIST_NEXT(ot, link);
173                 if (dns_name_equal(&ot->name, &(*tuplep)->name) &&
174                     dns_rdata_compare(&ot->rdata, &(*tuplep)->rdata) == 0 &&
175                     ot->ttl == (*tuplep)->ttl)
176                 {
177                         ISC_LIST_UNLINK(diff->tuples, ot, link);
178                         if ((*tuplep)->op == ot->op) {
179                                 UNEXPECTED_ERROR(__FILE__, __LINE__,
180                                          "unexpected non-minimal diff");
181                         } else {
182                                 dns_difftuple_free(tuplep);
183                         }
184                         dns_difftuple_free(&ot);
185                         break;
186                 }
187         }
188
189         if (*tuplep != NULL) {
190                 ISC_LIST_APPEND(diff->tuples, *tuplep, link);
191                 *tuplep = NULL;
192         }
193
194         ENSURE(*tuplep == NULL);
195 }
196
197 static isc_stdtime_t
198 setresign(dns_rdataset_t *modified, isc_uint32_t delta) {
199         dns_rdata_t rdata = DNS_RDATA_INIT;
200         dns_rdata_rrsig_t sig;
201         isc_stdtime_t when;
202         isc_result_t result;
203
204         result = dns_rdataset_first(modified);
205         INSIST(result == ISC_R_SUCCESS);
206         dns_rdataset_current(modified, &rdata);
207         (void)dns_rdata_tostruct(&rdata, &sig, NULL);
208         if ((rdata.flags & DNS_RDATA_OFFLINE) != 0)
209                 when = 0;
210         else
211                 when = sig.timeexpire - delta;
212         dns_rdata_reset(&rdata);
213
214         result = dns_rdataset_next(modified);
215         while (result == ISC_R_SUCCESS) {
216                 dns_rdataset_current(modified, &rdata);
217                 (void)dns_rdata_tostruct(&rdata, &sig, NULL);
218                 if ((rdata.flags & DNS_RDATA_OFFLINE) != 0) {
219                         goto next_rr;
220                 }
221                 if (when == 0 || sig.timeexpire - delta < when)
222                         when = sig.timeexpire - delta;
223  next_rr:
224                 dns_rdata_reset(&rdata);
225                 result = dns_rdataset_next(modified);
226         }
227         INSIST(result == ISC_R_NOMORE);
228         return (when);
229 }
230
231 static isc_result_t
232 diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver,
233            isc_boolean_t warn)
234 {
235         dns_difftuple_t *t;
236         dns_dbnode_t *node = NULL;
237         isc_result_t result;
238         char namebuf[DNS_NAME_FORMATSIZE];
239         char typebuf[DNS_RDATATYPE_FORMATSIZE];
240         char classbuf[DNS_RDATACLASS_FORMATSIZE];
241
242         REQUIRE(DNS_DIFF_VALID(diff));
243         REQUIRE(DNS_DB_VALID(db));
244
245         t = ISC_LIST_HEAD(diff->tuples);
246         while (t != NULL) {
247                 dns_name_t *name;
248
249                 INSIST(node == NULL);
250                 name = &t->name;
251                 /*
252                  * Find the node.
253                  * We create the node if it does not exist.
254                  * This will cause an empty node to be created if the diff
255                  * contains a deletion of an RR at a nonexistent name,
256                  * but such diffs should never be created in the first
257                  * place.
258                  */
259
260                 while (t != NULL && dns_name_equal(&t->name, name)) {
261                         dns_rdatatype_t type, covers;
262                         dns_diffop_t op;
263                         dns_rdatalist_t rdl;
264                         dns_rdataset_t rds;
265                         dns_rdataset_t ardataset;
266                         dns_rdataset_t *modified = NULL;
267
268                         op = t->op;
269                         type = t->rdata.type;
270                         covers = rdata_covers(&t->rdata);
271
272                         /*
273                          * Collect a contiguous set of updates with
274                          * the same operation (add/delete) and RR type
275                          * into a single rdatalist so that the
276                          * database rrset merging/subtraction code
277                          * can work more efficiently than if each
278                          * RR were merged into / subtracted from
279                          * the database separately.
280                          *
281                          * This is done by linking rdata structures from the
282                          * diff into "rdatalist".  This uses the rdata link
283                          * field, not the diff link field, so the structure
284                          * of the diff itself is not affected.
285                          */
286
287                         rdl.type = type;
288                         rdl.covers = covers;
289                         rdl.rdclass = t->rdata.rdclass;
290                         rdl.ttl = t->ttl;
291                         ISC_LIST_INIT(rdl.rdata);
292                         ISC_LINK_INIT(&rdl, link);
293
294                         node = NULL;
295                         if (type != dns_rdatatype_nsec3 &&
296                             covers != dns_rdatatype_nsec3)
297                                 CHECK(dns_db_findnode(db, name, ISC_TRUE,
298                                                       &node));
299                         else
300                                 CHECK(dns_db_findnsec3node(db, name, ISC_TRUE,
301                                                            &node));
302
303                         while (t != NULL &&
304                                dns_name_equal(&t->name, name) &&
305                                t->op == op &&
306                                t->rdata.type == type &&
307                                rdata_covers(&t->rdata) == covers)
308                         {
309                                 dns_name_format(name, namebuf, sizeof(namebuf));
310                                 dns_rdatatype_format(t->rdata.type, typebuf,
311                                                      sizeof(typebuf));
312                                 dns_rdataclass_format(t->rdata.rdclass,
313                                                       classbuf,
314                                                       sizeof(classbuf));
315                                 if (t->ttl != rdl.ttl && warn)
316                                         isc_log_write(DIFF_COMMON_LOGARGS,
317                                                 ISC_LOG_WARNING,
318                                                 "'%s/%s/%s': TTL differs in "
319                                                 "rdataset, adjusting "
320                                                 "%lu -> %lu",
321                                                 namebuf, typebuf, classbuf,
322                                                 (unsigned long) t->ttl,
323                                                 (unsigned long) rdl.ttl);
324                                 ISC_LIST_APPEND(rdl.rdata, &t->rdata, link);
325                                 t = ISC_LIST_NEXT(t, link);
326                         }
327
328                         /*
329                          * Convert the rdatalist into a rdataset.
330                          */
331                         dns_rdataset_init(&rds);
332                         CHECK(dns_rdatalist_tordataset(&rdl, &rds));
333                         if (rds.type == dns_rdatatype_rrsig)
334                                 switch (op) {
335                                 case DNS_DIFFOP_ADDRESIGN:
336                                 case DNS_DIFFOP_DELRESIGN:
337                                         modified = &ardataset;
338                                         dns_rdataset_init(modified);
339                                         break;
340                                 default:
341                                         break;
342                                 }
343                         rds.trust = dns_trust_ultimate;
344
345                         /*
346                          * Merge the rdataset into the database.
347                          */
348                         switch (op) {
349                         case DNS_DIFFOP_ADD:
350                         case DNS_DIFFOP_ADDRESIGN:
351                                 result = dns_db_addrdataset(db, node, ver,
352                                                             0, &rds,
353                                                             DNS_DBADD_MERGE|
354                                                             DNS_DBADD_EXACT|
355                                                             DNS_DBADD_EXACTTTL,
356                                                             modified);
357                                 break;
358                         case DNS_DIFFOP_DEL:
359                         case DNS_DIFFOP_DELRESIGN:
360                                 result = dns_db_subtractrdataset(db, node, ver,
361                                                                &rds,
362                                                                DNS_DBSUB_EXACT,
363                                                                modified);
364                                 break;
365                         default:
366                                 INSIST(0);
367                         }
368
369                         if (result == ISC_R_SUCCESS) {
370                                 if (modified != NULL) {
371                                         isc_stdtime_t resign;
372                                         resign = setresign(modified,
373                                                            diff->resign);
374                                         dns_db_setsigningtime(db, modified,
375                                                               resign);
376                                 }
377                         } else if (result == DNS_R_UNCHANGED) {
378                                 /*
379                                  * This will not happen when executing a
380                                  * dynamic update, because that code will
381                                  * generate strictly minimal diffs.
382                                  * It may happen when receiving an IXFR
383                                  * from a server that is not as careful.
384                                  * Issue a warning and continue.
385                                  */
386                                 if (warn) {
387                                         char classbuf[DNS_RDATATYPE_FORMATSIZE];
388                                         char namebuf[DNS_NAME_FORMATSIZE];
389
390                                         dns_name_format(dns_db_origin(db),
391                                                         namebuf,
392                                                         sizeof(namebuf));
393                                         dns_rdataclass_format(dns_db_class(db),
394                                                               classbuf,
395                                                               sizeof(classbuf));
396                                         isc_log_write(DIFF_COMMON_LOGARGS,
397                                                       ISC_LOG_WARNING,
398                                                       "%s/%s: dns_diff_apply: "
399                                                       "update with no effect",
400                                                       namebuf, classbuf);
401                                 }
402                         } else if (result == DNS_R_NXRRSET) {
403                                 /*
404                                  * OK.
405                                  */
406                         } else {
407                                 if (modified != NULL &&
408                                     dns_rdataset_isassociated(modified))
409                                         dns_rdataset_disassociate(modified);
410                                 CHECK(result);
411                         }
412                         dns_db_detachnode(db, &node);
413                         if (modified != NULL &&
414                             dns_rdataset_isassociated(modified))
415                                 dns_rdataset_disassociate(modified);
416                 }
417         }
418         return (ISC_R_SUCCESS);
419
420  failure:
421         if (node != NULL)
422                 dns_db_detachnode(db, &node);
423         return (result);
424 }
425
426 isc_result_t
427 dns_diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver) {
428         return (diff_apply(diff, db, ver, ISC_TRUE));
429 }
430
431 isc_result_t
432 dns_diff_applysilently(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver) {
433         return (diff_apply(diff, db, ver, ISC_FALSE));
434 }
435
436 /* XXX this duplicates lots of code in diff_apply(). */
437
438 isc_result_t
439 dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
440               void *add_private)
441 {
442         dns_difftuple_t *t;
443         isc_result_t result;
444
445         REQUIRE(DNS_DIFF_VALID(diff));
446
447         t = ISC_LIST_HEAD(diff->tuples);
448         while (t != NULL) {
449                 dns_name_t *name;
450
451                 name = &t->name;
452                 while (t != NULL && dns_name_equal(&t->name, name)) {
453                         dns_rdatatype_t type, covers;
454                         dns_diffop_t op;
455                         dns_rdatalist_t rdl;
456                         dns_rdataset_t rds;
457
458                         op = t->op;
459                         type = t->rdata.type;
460                         covers = rdata_covers(&t->rdata);
461
462                         rdl.type = type;
463                         rdl.covers = covers;
464                         rdl.rdclass = t->rdata.rdclass;
465                         rdl.ttl = t->ttl;
466                         ISC_LIST_INIT(rdl.rdata);
467                         ISC_LINK_INIT(&rdl, link);
468
469                         while (t != NULL && dns_name_equal(&t->name, name) &&
470                                t->op == op && t->rdata.type == type &&
471                                rdata_covers(&t->rdata) == covers)
472                         {
473                                 ISC_LIST_APPEND(rdl.rdata, &t->rdata, link);
474                                 t = ISC_LIST_NEXT(t, link);
475                         }
476
477                         /*
478                          * Convert the rdatalist into a rdataset.
479                          */
480                         dns_rdataset_init(&rds);
481                         CHECK(dns_rdatalist_tordataset(&rdl, &rds));
482                         rds.trust = dns_trust_ultimate;
483
484                         INSIST(op == DNS_DIFFOP_ADD);
485                         result = (*addfunc)(add_private, name, &rds);
486                         if (result == DNS_R_UNCHANGED) {
487                                 isc_log_write(DIFF_COMMON_LOGARGS,
488                                               ISC_LOG_WARNING,
489                                               "dns_diff_load: "
490                                               "update with no effect");
491                         } else if (result == ISC_R_SUCCESS ||
492                                    result == DNS_R_NXRRSET) {
493                                 /*
494                                  * OK.
495                                  */
496                         } else {
497                                 CHECK(result);
498                         }
499                 }
500         }
501         result = ISC_R_SUCCESS;
502  failure:
503         return (result);
504 }
505
506 /*
507  * XXX uses qsort(); a merge sort would be more natural for lists,
508  * and perhaps safer wrt thread stack overflow.
509  */
510 isc_result_t
511 dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) {
512         unsigned int length = 0;
513         unsigned int i;
514         dns_difftuple_t **v;
515         dns_difftuple_t *p;
516         REQUIRE(DNS_DIFF_VALID(diff));
517
518         for (p = ISC_LIST_HEAD(diff->tuples);
519              p != NULL;
520              p = ISC_LIST_NEXT(p, link))
521                 length++;
522         if (length == 0)
523                 return (ISC_R_SUCCESS);
524         v = isc_mem_get(diff->mctx, length * sizeof(dns_difftuple_t *));
525         if (v == NULL)
526                 return (ISC_R_NOMEMORY);
527         for (i = 0; i < length; i++) {
528                 p = ISC_LIST_HEAD(diff->tuples);
529                 v[i] = p;
530                 ISC_LIST_UNLINK(diff->tuples, p, link);
531         }
532         INSIST(ISC_LIST_HEAD(diff->tuples) == NULL);
533         qsort(v, length, sizeof(v[0]), compare);
534         for (i = 0; i < length; i++) {
535                 ISC_LIST_APPEND(diff->tuples, v[i], link);
536         }
537         isc_mem_put(diff->mctx, v, length * sizeof(dns_difftuple_t *));
538         return (ISC_R_SUCCESS);
539 }
540
541
542 /*
543  * Create an rdataset containing the single RR of the given
544  * tuple.  The caller must allocate the rdata, rdataset and
545  * an rdatalist structure for it to refer to.
546  */
547
548 static isc_result_t
549 diff_tuple_tordataset(dns_difftuple_t *t, dns_rdata_t *rdata,
550                       dns_rdatalist_t *rdl, dns_rdataset_t *rds)
551 {
552         REQUIRE(DNS_DIFFTUPLE_VALID(t));
553         REQUIRE(rdl != NULL);
554         REQUIRE(rds != NULL);
555
556         rdl->type = t->rdata.type;
557         rdl->rdclass = t->rdata.rdclass;
558         rdl->ttl = t->ttl;
559         ISC_LIST_INIT(rdl->rdata);
560         ISC_LINK_INIT(rdl, link);
561         dns_rdataset_init(rds);
562         ISC_LINK_INIT(rdata, link);
563         dns_rdata_clone(&t->rdata, rdata);
564         ISC_LIST_APPEND(rdl->rdata, rdata, link);
565         return (dns_rdatalist_tordataset(rdl, rds));
566 }
567
568 isc_result_t
569 dns_diff_print(dns_diff_t *diff, FILE *file) {
570         isc_result_t result;
571         dns_difftuple_t *t;
572         char *mem = NULL;
573         unsigned int size = 2048;
574         const char *op = NULL;
575
576         REQUIRE(DNS_DIFF_VALID(diff));
577
578         mem = isc_mem_get(diff->mctx, size);
579         if (mem == NULL)
580                 return (ISC_R_NOMEMORY);
581
582         for (t = ISC_LIST_HEAD(diff->tuples); t != NULL;
583              t = ISC_LIST_NEXT(t, link))
584         {
585                 isc_buffer_t buf;
586                 isc_region_t r;
587
588                 dns_rdatalist_t rdl;
589                 dns_rdataset_t rds;
590                 dns_rdata_t rd = DNS_RDATA_INIT;
591
592                 result = diff_tuple_tordataset(t, &rd, &rdl, &rds);
593                 if (result != ISC_R_SUCCESS) {
594                         UNEXPECTED_ERROR(__FILE__, __LINE__,
595                                          "diff_tuple_tordataset failed: %s",
596                                          dns_result_totext(result));
597                         result =  ISC_R_UNEXPECTED;
598                         goto cleanup;
599                 }
600  again:
601                 isc_buffer_init(&buf, mem, size);
602                 result = dns_rdataset_totext(&rds, &t->name,
603                                              ISC_FALSE, ISC_FALSE, &buf);
604
605                 if (result == ISC_R_NOSPACE) {
606                         isc_mem_put(diff->mctx, mem, size);
607                         size += 1024;
608                         mem = isc_mem_get(diff->mctx, size);
609                         if (mem == NULL) {
610                                 result = ISC_R_NOMEMORY;
611                                 goto cleanup;
612                         }
613                         goto again;
614                 }
615
616                 if (result != ISC_R_SUCCESS)
617                         goto cleanup;
618                 /*
619                  * Get rid of final newline.
620                  */
621                 INSIST(buf.used >= 1 &&
622                        ((char *) buf.base)[buf.used-1] == '\n');
623                 buf.used--;
624
625                 isc_buffer_usedregion(&buf, &r);
626                 switch (t->op) {
627                 case DNS_DIFFOP_EXISTS: op = "exists"; break;
628                 case DNS_DIFFOP_ADD: op = "add"; break;
629                 case DNS_DIFFOP_DEL: op = "del"; break;
630                 case DNS_DIFFOP_ADDRESIGN: op = "add re-sign"; break;
631                 case DNS_DIFFOP_DELRESIGN: op = "del re-sign"; break;
632                 }
633                 if (file != NULL)
634                         fprintf(file, "%s %.*s\n", op, (int) r.length,
635                                 (char *) r.base);
636                 else
637                         isc_log_write(DIFF_COMMON_LOGARGS, ISC_LOG_DEBUG(7),
638                                       "%s %.*s", op, (int) r.length,
639                                       (char *) r.base);
640         }
641         result = ISC_R_SUCCESS;
642  cleanup:
643         if (mem != NULL)
644                 isc_mem_put(diff->mctx, mem, size);
645         return (result);
646 }