Commit 524d0e74 authored by Daniel Sommermann's avatar Daniel Sommermann Committed by Peter Griess

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
parent 762965ce
...@@ -238,7 +238,9 @@ class IOBuf { ...@@ -238,7 +238,9 @@ class IOBuf {
* buffer as the first argument, and the supplied userData value as the * buffer as the first argument, and the supplied userData value as the
* second argument. The free function must never throw exceptions. * 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, * The IOBuf data pointer will initially point to the start of the buffer,
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment