+/* Returns the data in 'b' as a block of malloc()'d memory and frees the buffer
+ * within 'b'. (If 'b' itself was dynamically allocated, e.g. with
+ * ofpbuf_new(), then it should still be freed with, e.g., ofpbuf_delete().) */
+void *
+ofpbuf_steal_data(struct ofpbuf *b)
+{
+ void *p;
+ if (b->source == OFPBUF_MALLOC && b->data == b->base) {
+ p = b->data;
+ } else {
+ p = xmemdup(b->data, b->size);
+ if (b->source == OFPBUF_MALLOC) {
+ free(b->base);
+ }
+ }
+ b->base = b->data = NULL;
+ return p;
+}
+