in src/constbuffer.c [352:377]
static void CONSTBUFFER_DecRef_internal(CONSTBUFFER_HANDLE constbufferHandle)
{
/*Codes_SRS_CONSTBUFFER_02_016: [Otherwise, CONSTBUFFER_DecRef shall decrement the refcount on the constbufferHandle handle.]*/
if (interlocked_decrement(&constbufferHandle->count) == 0)
{
if (constbufferHandle->buffer_type == CONSTBUFFER_TYPE_MEMORY_MOVED)
{
free((void*)constbufferHandle->alias.buffer);
}
else if (constbufferHandle->buffer_type == CONSTBUFFER_TYPE_WITH_CUSTOM_FREE)
{
CONSTBUFFER_HANDLE_WITH_CUSTOM_FREE_DATA* handleData = (CONSTBUFFER_HANDLE_WITH_CUSTOM_FREE_DATA*)constbufferHandle;
/* Codes_SRS_CONSTBUFFER_01_012: [ If the buffer was created by calling CONSTBUFFER_CreateWithCustomFree, the customFreeFunc function shall be called to free the memory, while passed customFreeFuncContext as argument. ]*/
handleData->custom_free_func(handleData->custom_free_func_context);
}
/*Codes_SRS_CONSTBUFFER_02_024: [ If the constbufferHandle was created by calling CONSTBUFFER_CreateFromOffsetAndSize then CONSTBUFFER_DecRef shall decrement the ref count of the original handle passed to CONSTBUFFER_CreateFromOffsetAndSize. ]*/
else if (constbufferHandle->buffer_type == CONSTBUFFER_TYPE_FROM_OFFSET_AND_SIZE)
{
CONSTBUFFER_HANDLE_FROM_OFFSET_AND_SIZE_DATA* handleData = (CONSTBUFFER_HANDLE_FROM_OFFSET_AND_SIZE_DATA*)constbufferHandle;
CONSTBUFFER_DecRef_internal(handleData->originalHandle);
}
/*Codes_SRS_CONSTBUFFER_02_017: [If the refcount reaches zero, then CONSTBUFFER_DecRef shall deallocate all resources used by the CONSTBUFFER_HANDLE.]*/
free(constbufferHandle);
}
}