Bug in memory program

Issue #153 resolved
Patryk Kubiak created an issue

There is a bug in memory program. This:

#!c

        while(errorCode == oC_ErrorCode_OutputArrayToSmall)
        {
            stats = smartalloc(sizeof(oC_MemMan_AllocatorsStats_t) * size , AllocationFlags_ZeroFill);

            if(stats != NULL)
            {
                errorCode = oC_MemMan_ReadAllocatorsStats(stats,&size);

                if(errorCode == oC_ErrorCode_OutputArrayToSmall)
                {
                    smartfree(stats,sizeof(oC_MemMan_AllocatorsStats_t) * size ,AllocationFlags_Default);
                    size *= 2;
                }
            }
            else
            {
                errorCode = oC_ErrorCode_AllocationError;
            }
        }

Should be:

#!c
        while(errorCode == oC_ErrorCode_OutputArrayToSmall)
        {
            uint32_t tempSize = size;
            stats = smartalloc(sizeof(oC_MemMan_AllocatorsStats_t) * size, AllocationFlags_ZeroFill);

            if(stats != NULL)
            {
                errorCode = oC_MemMan_ReadAllocatorsStats(stats,&tempSize);

                if(errorCode == oC_ErrorCode_OutputArrayToSmall)
                {
                    smartfree(stats,sizeof(oC_MemMan_AllocatorsStats_t) * size ,AllocationFlags_Default);
                    size *= 2;
                }
            }
            else
            {
                errorCode = oC_ErrorCode_AllocationError;
            }
        }

Comments (3)

  1. Log in to comment