Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7199

Dynamic allocated Array of structs cant be freed

$
0
0

I have this array:

//array of Runways(Runway is a struct)
Runway* arrOfRunways_All = (Runway*)malloc(sizeof(Runway));

I can't free my dynamic allocated memory array, I noticed that after this part of the code:

int NumOfRunways_All = 0;
//copying all runways to an array, counting runways
while (curRunway != NULL) {
    //copying all runways to an array, counting runways
    arrOfRunways_All[NumOfRunways_All] = *curRunway;
    NumOfRunways_All++;
    if (iterator->pNext == NULL) {
        break;
    }
    pAirport tmp = iterator->pNext;
    iterator = tmp;
    curRunway = iterator->runway;
}

free(arrOfRunways_All);

I get crashed. I checked over and over, it cant be dangling pointer. IDK what else can it be.

Thank you very much;


Viewing all articles
Browse latest Browse all 7199

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>