This is an automated email from the ASF dual-hosted git repository.

jiashunzhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new d0052a60 Early return for IOBuf::append_user_data when size == 0 
(#2009)
d0052a60 is described below

commit d0052a601f451ebf8d45505a9199a813d943acac
Author: 372046933 <372046...@users.noreply.github.com>
AuthorDate: Tue Nov 29 06:27:19 2022 +0800

    Early return for IOBuf::append_user_data when size == 0 (#2009)
---
 src/butil/iobuf.cpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/butil/iobuf.cpp b/src/butil/iobuf.cpp
index b468e91d..cb22554a 100644
--- a/src/butil/iobuf.cpp
+++ b/src/butil/iobuf.cpp
@@ -1211,13 +1211,17 @@ int IOBuf::append_user_data(void* data, size_t size, 
void (*deleter)(void*)) {
         LOG(FATAL) << "data_size=" << size << " is too large";
         return -1;
     }
+    if (!deleter) {
+        deleter = ::free;
+    }
+    if (!size) {
+        deleter(data);
+        return 0;
+    }
     char* mem = (char*)malloc(sizeof(IOBuf::Block) + 
sizeof(UserDataExtension));
     if (mem == NULL) {
         return -1;
     }
-    if (deleter == NULL) {
-        deleter = ::free;
-    }
     IOBuf::Block* b = new (mem) IOBuf::Block((char*)data, size, deleter);
     const IOBuf::BlockRef r = { 0, b->cap, b };
     _move_back_ref(r);


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to