1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 #include "oic_malloc.h"
27 // Enable extra debug logging for malloc. Comment out to disable
28 #ifdef ENABLE_MALLOC_DEBUG
30 #define TAG "OICMalloc"
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
46 // Internal API function
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
50 // Private internal function prototypes
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
56 #ifdef ENABLE_MALLOC_DEBUG
57 static uint32_t count;
60 void *OICMalloc(size_t size)
62 #ifdef ENABLE_MALLOC_DEBUG
72 OIC_LOG_V(INFO, TAG, "malloc: ptr=%p, size=%u, count=%u", ptr, size, count);
83 void *OICCalloc(size_t num, size_t size)
85 if(0 == size || 0 == num)
90 #ifdef ENABLE_MALLOC_DEBUG
93 ptr = calloc(num, size);
94 OIC_LOG_V(INFO, TAG, "calloc: ptr=%p, num=%u, size=%u", ptr, num, size);
97 return calloc(num, size);
101 void OICFree(void *ptr)
103 #ifdef ENABLE_MALLOC_DEBUG
104 OIC_LOG_V(INFO, TAG, "free: ptr=%p, count=%u", ptr, --count);