#Exit code -1073740940 (0xC0000374) - Heap Corruption?

9 messages · Page 1 of 1 (latest)

tired fiber
#

So I finished a project I've been working on for my C++ course in college, and I've run into an error I haven't seen before. I googled the code (0xC0000374) and apparently its related to heap corruption.. I then understood this is much above my head

I have dynamically allocated memory, but I did delete all memory that was allocated at the end of my program. Here is the relevant code:

main.cpp

    // create a roster class instance with 5 student objects
    Roster *classRoster = new Roster(5);

then calls
roster.cpp

// constructor
Roster::Roster(int class_size) {
    this->classSize = class_size;
    this->index = 0;
    for (int i = 0; i < this->classSize; i++) {
        this->classRosterArray[i] = new Student;
    }
}

I then call various getters/setters and member functions that do not handle memory allocation. This is my destructor.

// deallocate memory that was dynamically allocated
Roster::~Roster() {
    for (int i = 0; i < this->classSize; i++) {
        delete this->classRosterArray[i];
    }
}

Which is called at the end of main.cpp

    // call destructor and clean allocated memory
    classRoster->~Roster();
    delete classRoster;

    return 0;

What have I missed here? All output from the program is normal, only the exit code is incorrect.

lime lodgeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

tired fiber
#

Only other part of my program that could cause errors (that I know of)

// removes a student from the roster
void Roster::remove(std::string studentID) {
    bool studentExists = false;
    // iterate through all students
    for (int i = 0; i < this->classSize; i++) {
        if (this->classRosterArray[i] == nullptr) {
            continue;
        } else if (studentID == this->classRosterArray[i]->getID()) {
            this->classRosterArray[i] = nullptr;
            studentExists = true;
            break;
        }
    }
    if (studentExists == false) {
        std::cout << "Error: Student " << studentID << " not found." << std::endl;
    } else {
        std::cout << "Student " << studentID << " successfully removed.";
    }
}
#

This nullifies all the data but does not delete the allocated space (because that is done at the end of the program).

#

I uh figured it out and feel really dumb

#

Apparently calling delete also calls the destructor

#

So I was destructing nothing

#

~solved

#

!solved