Add a comment about takeOwnership()
authorDaniel Sommermann <dcsommer@fb.com>
Mon, 30 Sep 2013 21:02:07 +0000 (14:02 -0700)
committerPeter Griess <pgriess@fb.com>
Tue, 15 Oct 2013 01:44:21 +0000 (18:44 -0700)
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

folly/io/IOBuf.h

index 3473d05e155161af9284007c5f618f7c9417c70f..7d96e02f542f906f3d5e9300838cb59ca4ceea94 100644 (file)
@@ -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,
    *