From: Daniel Sommermann Date: Mon, 30 Sep 2013 21:02:07 +0000 (-0700) Subject: Add a comment about takeOwnership() X-Git-Tag: v0.22.0~858 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=524d0e74dbcd615e3704be2a119cd63f6c69d3fd;p=folly.git Add a comment about takeOwnership() Summary: It is dangerous to pass memory into an IOBuf since usually in C++ programs, memory is allocated using `new`, while IOBuf by default frees memory that it has taken ownership of with `free()`. For now, add a comment warning about this (address sanitizer will warn you about this when it happens in a live process). Test Plan: NA Reviewed By: tudorb@fb.com FB internal diff: D990056 @override-unit-failures --- diff --git a/folly/io/IOBuf.h b/folly/io/IOBuf.h index 3473d05e..7d96e02f 100644 --- a/folly/io/IOBuf.h +++ b/folly/io/IOBuf.h @@ -238,7 +238,9 @@ class IOBuf { * buffer as the first argument, and the supplied userData value as the * second argument. The free function must never throw exceptions. * - * If no FreeFunction is specified, the buffer will be freed using free(). + * If no FreeFunction is specified, the buffer will be freed using free() + * which will result in undefined behavior if the memory was allocated + * using 'new'. * * The IOBuf data pointer will initially point to the start of the buffer, *