From 01a1b809dd8da86a62381530f896752f737fe673 Mon Sep 17 00:00:00 2001 From: huangyicong Date: Mon, 18 Apr 2022 18:13:11 +0800 Subject: [PATCH 1/6] fix realloc Signed-off-by: huangyicong --- base/src/parcel.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/base/src/parcel.cpp b/base/src/parcel.cpp index 855f7cf..026a74e 100644 --- a/base/src/parcel.cpp +++ b/base/src/parcel.cpp @@ -16,6 +16,7 @@ #include "parcel.h" #include "securec.h" #include "utils_log.h" +#include namespace OHOS { @@ -580,7 +581,7 @@ bool Parcel::EnsureObjectsCapacity() size_t newCapacity = ((objectsCapacity_ + NEW_CAPACITY_ADD) * NEW_CAPACITY_MULTI) / NEW_CAPACITY_DIV; size_t newBytes = newCapacity * sizeof(binder_size_t); - void *newOffsets = realloc(objectOffsets_, newBytes); + void *newOffsets = allocator_->Realloc(objectOffsets_, newBytes); if (newOffsets == nullptr) { return false; } @@ -1131,7 +1132,21 @@ void DefaultAllocator::Dealloc(void *data) void *DefaultAllocator::Realloc(void *data, size_t newSize) { - return realloc(data, newSize); + if (newSize != 0) { + void *newData = malloc(newSize); + if (newData != nullptr) { + if (data == nullptr) { + return newData; + } else if (memcpy_s(newData, newSize, data, malloc_usable_size(data)) == EOK) { + free(data); + return newData; + } + free(newData); + } + UTILS_LOGW("Realloc failed!"); + } + free(data); + return nullptr; } template -- Gitee From c7140a65cb4e0a829937d257fbcdd5002fb6c348 Mon Sep 17 00:00:00 2001 From: huangyicong Date: Tue, 19 Apr 2022 09:29:28 +0800 Subject: [PATCH 2/6] fix realloc Signed-off-by: huangyicong --- base/src/parcel.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/base/src/parcel.cpp b/base/src/parcel.cpp index 026a74e..34726c5 100644 --- a/base/src/parcel.cpp +++ b/base/src/parcel.cpp @@ -13,10 +13,10 @@ * limitations under the License. */ +#include #include "parcel.h" #include "securec.h" #include "utils_log.h" -#include namespace OHOS { @@ -1133,6 +1133,9 @@ void DefaultAllocator::Dealloc(void *data) void *DefaultAllocator::Realloc(void *data, size_t newSize) { if (newSize != 0) { + if (newSize > maxDataCapacity_) { + newSize = maxDataCapacity_; + } void *newData = malloc(newSize); if (newData != nullptr) { if (data == nullptr) { -- Gitee From 3df226d29fce7fe7498d392073bb0bd5964d672c Mon Sep 17 00:00:00 2001 From: huangyicong Date: Tue, 19 Apr 2022 12:35:01 +0800 Subject: [PATCH 3/6] fix realloc Signed-off-by: huangyicong --- base/src/parcel.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base/src/parcel.cpp b/base/src/parcel.cpp index 34726c5..87ccbc1 100644 --- a/base/src/parcel.cpp +++ b/base/src/parcel.cpp @@ -14,9 +14,9 @@ */ #include -#include "parcel.h" #include "securec.h" #include "utils_log.h" +#include "parcel.h" namespace OHOS { @@ -1133,8 +1133,8 @@ void DefaultAllocator::Dealloc(void *data) void *DefaultAllocator::Realloc(void *data, size_t newSize) { if (newSize != 0) { - if (newSize > maxDataCapacity_) { - newSize = maxDataCapacity_; + if (newSize > DEFAULT_CPACITY) { + newSize = DEFAULT_CPACITY; } void *newData = malloc(newSize); if (newData != nullptr) { -- Gitee From 181a26f7a17c2972703da99ce44d5b1f2fb92808 Mon Sep 17 00:00:00 2001 From: huangyicong Date: Sun, 24 Apr 2022 14:36:12 +0800 Subject: [PATCH 4/6] fix realloc Signed-off-by: huangyicong --- base/src/parcel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/src/parcel.cpp b/base/src/parcel.cpp index 87ccbc1..2af70d8 100644 --- a/base/src/parcel.cpp +++ b/base/src/parcel.cpp @@ -1140,7 +1140,8 @@ void *DefaultAllocator::Realloc(void *data, size_t newSize) if (newData != nullptr) { if (data == nullptr) { return newData; - } else if (memcpy_s(newData, newSize, data, malloc_usable_size(data)) == EOK) { + } + if (memcpy_s(newData, newSize, data, malloc_usable_size(data)) == EOK) { free(data); return newData; } @@ -1148,7 +1149,6 @@ void *DefaultAllocator::Realloc(void *data, size_t newSize) } UTILS_LOGW("Realloc failed!"); } - free(data); return nullptr; } -- Gitee From 7c0111c0ba7c2370c6e8b1d0103aee0fa6712948 Mon Sep 17 00:00:00 2001 From: huangyicong Date: Sun, 24 Apr 2022 15:16:39 +0800 Subject: [PATCH 5/6] fix realloc Signed-off-by: huangyicong --- base/src/parcel.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/base/src/parcel.cpp b/base/src/parcel.cpp index 2af70d8..d203b0a 100644 --- a/base/src/parcel.cpp +++ b/base/src/parcel.cpp @@ -1149,6 +1149,7 @@ void *DefaultAllocator::Realloc(void *data, size_t newSize) } UTILS_LOGW("Realloc failed!"); } + free(data); return nullptr; } -- Gitee From 22dd9aa1135a7111c3c696a8f5333965376366f3 Mon Sep 17 00:00:00 2001 From: huangyicong Date: Mon, 25 Apr 2022 15:39:18 +0800 Subject: [PATCH 6/6] fix realloc Signed-off-by: huangyicong --- base/src/parcel.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/base/src/parcel.cpp b/base/src/parcel.cpp index d203b0a..6fdaaaa 100644 --- a/base/src/parcel.cpp +++ b/base/src/parcel.cpp @@ -1133,9 +1133,6 @@ void DefaultAllocator::Dealloc(void *data) void *DefaultAllocator::Realloc(void *data, size_t newSize) { if (newSize != 0) { - if (newSize > DEFAULT_CPACITY) { - newSize = DEFAULT_CPACITY; - } void *newData = malloc(newSize); if (newData != nullptr) { if (data == nullptr) { @@ -1149,7 +1146,6 @@ void *DefaultAllocator::Realloc(void *data, size_t newSize) } UTILS_LOGW("Realloc failed!"); } - free(data); return nullptr; } -- Gitee