return (int)to_copy;
}
+/** Detach both dbuffs from the shared backing buffer
+ *
+ * The in/out dbuffs are bound to the same talloc buffer, so when the buffer
+ * is freed, or ownership is handed to a caller, both dbuffs must forget the
+ * buffer together. A stale sibling pointer double-frees in the destructor,
+ * or trips the "BIO not finalised" assert on reuse.
+ */
+static inline CC_HINT(always_inline) void tls_bio_dbuff_detach(fr_tls_bio_dbuff_t *bd)
+{
+ bd->dbuff_in.buff = NULL;
+ bd->dbuff_out.buff = NULL;
+}
+
/** Finalise a talloc aggregation buffer, returning the underlying talloc array holding the data
*
* @return
fr_dbuff_trim_talloc(&bd->dbuff_in, SIZE_MAX);
buff = bd->dbuff_in.buff;
- bd->dbuff_in.buff = NULL;
- bd->dbuff_out.buff = NULL;
+ tls_bio_dbuff_detach(bd);
return buff;
}
fr_dbuff_trim_talloc(&bd->dbuff_in, SIZE_MAX);
buff = bd->dbuff_in.buff;
- bd->dbuff_in.buff = NULL;
- bd->dbuff_out.buff = NULL;
+ tls_bio_dbuff_detach(bd);
talloc_set_type(buff, char);
return (char *)buff;
if (unlikely(!bd->dbuff_in.buff)) return;
fr_dbuff_free_talloc(&bd->dbuff_in);
- bd->dbuff_out.buff = NULL;
+ tls_bio_dbuff_detach(bd);
}
/** Frees the thread local TALLOC bio and its underlying OpenSSL BIO *