Fix incorrect memory allocation in GPIO

Issue #258 new
Patryk Kubiak created an issue

Following functions in gpio allocates memory without a reason, and causes memory leak:

const char * oC_GPIO_GetPullNameFromEnum(oC_GPIO_Pull_t Pull)
{
    char * name = malloc(sizeof(name)   , 10);

    switch(Pull)
    {
        case oC_GPIO_Pull_Default:
            name = "Default";
            break;
        case oC_GPIO_Pull_Down:
            name = "Down";
            break;
        case oC_GPIO_Pull_Up:
            name = "Up";
            break;
        default:
            name = "Unknown";
            break;
    }

    free(&name, AllocationFlags_Default);
    return name;
}


oC_GPIO_GetCurrentNameFromEnum
oC_GPIO_GetModeNameFromEnum
oC_GPIO_GetOutputCircuitNameFromEnum
oC_GPIO_GetPullNameFromEnum
oC_GPIO_GetSpeedNameFromEnum
oC_GPIO_GetIntTriggerNameFromEnum

Comments (0)

  1. Log in to comment