Can not allocate memory in heap

Viewed 77

For some reason this part of code produce the following error:

malloc.c:4302: _int_malloc: Assertion `(unsigned long) (size) >= (unsigned long) (nb)' failed.
Aborted (core dumped)
         

The code:

//car_type.h
typedef struct car_type{
     int type;
     const char* type;}car_type
     car_type **CarTypes;


  //car_types.cpp
         CarTypes = nullptr;
     
  //main.cpp
     int main(){
     CarTypes = new car_type*[50];
     for(int i =0; i < 50; i++)
            {
                CarTypes[i] = nullptr;
            }
      
     int index = 0;
some_string = "some_string";
some_string_holding_int = "1";
     while(index < 10)
                {
                    cout<< index<<endl;
                    car_type *temp = new car_type;
                    temp->type_int  = stoi(some_string_holding_int);
                    temp->type_string = some_string;
                    cout<< "I never get here" <<endl;
                    CarTypes[index]= temp;
                        index++;
                    
                }
}...

I feel very frustrated. When I tried to heap allocate any class, type etc.etc. inside this part of my code, even with string constructor the result is the same. What could make such strange behaviour? I did not allocate big amout of dynamic memory. If there is some need of more code review i will upload, but the point is my program works alright when this part is not included. Could you help me?

0 Answers
Related