Skip to content

Memory violation in free_*_struct function when using unions #69

@burgerkingorama

Description

@burgerkingorama

Hello!

When using an union within a struct the free-function does not handle all switch-cases but only those that needs special sub-free-calls like list<> etc. Unfortunately this free calls is then always performed regardless of which union type was used at that moment.

Example eRPC IDL:

struct TestStruct
{
	int32 handle_count // uint32 handle_count causes error in eRPC code
    union(handle_count)
	{
	case 0:
		uint16 start_handle
		uint16 end_handle
	case 1:
		uint16 handle
		uint16 offset
	default:
		list<uint16> handles
	} range
}

The free call looks like this:

static void free_TestStruct_struct(TestStruct * data)
{
    switch (data->handle_count)
    {
        default:
        {
            free_list_uint16_1_t_struct(&data->range.handles);
            break;
        }
    }
}

This will lead to memory violation if the list was not in use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions