void umocktypes_free()

in src/umocktypes.c [486:525]


void umocktypes_free(const char* type, void* value)
{
    /* Codes_SRS_UMOCKTYPES_01_031: [ If any of the arguments is NULL, umocktypes_free shall do nothing. ]*/
    if ((type != NULL) &&
        (value != NULL) &&
        /* Codes_SRS_UMOCKTYPES_01_048: [ If umocktypes_free is called when the module is not initialized, umocktypes_free shall do nothing. ]*/
        (umocktypes_state == UMOCKTYPES_STATE_INITIALIZED))
    {
        /* Codes_SRS_UMOCKTYPES_01_038: [ Before looking it up, the type string shall be normalized by calling umocktypename_normalize. ]*/
        char* normalized_type = umocktypename_normalize(type);
        if (normalized_type == NULL)
        {
            /* Codes_SRS_UMOCKTYPES_01_041: [ If normalizing the typename fails, umocktypes_free shall do nothing. ]*/
        }
        else
        {
            size_t normalized_type_length = strlen(normalized_type);
            UMOCK_VALUE_TYPE_HANDLERS* value_type_handlers = get_value_type_handlers(normalized_type);

            /* Codes_SRS_UMOCK_C_LIB_01_153: [ If no custom handler has beed registered for a pointer type, it shall be trated as void*. ] */
            if ((value_type_handlers == NULL) && (normalized_type[normalized_type_length - 1] == '*'))
            {
                /* Codes_SRS_UMOCKTYPES_01_066: [ If type is a pointer type and type was not registered then umocktypes_free shall execute as if type is void*. ]*/
                value_type_handlers = get_value_type_handlers("void*");
            }

            if (value_type_handlers == NULL)
            {
                /* Codes_SRS_UMOCKTYPES_01_032: [ If type can not be found in the registered types list maintained by the module, umocktypes_free shall do nothing. ]*/
            }
            else
            {
                /* Codes_SRS_UMOCKTYPES_01_033: [ The free shall be done by calling the underlying free function (passed in umocktypes_register_type) for the type identified by the type argument. ]*/
                value_type_handlers->free_func(value);
            }

            umockalloc_free(normalized_type);
        }
    }
}