<commit_before>#include "mbc1.h"

namespace gameboy {
namespace mbc {
MBC1::MBC1(uint8_t **romBanks, uint8_t num) :
    romBanks(romBanks),
    numOfROMBanks(num),
    currentROMBank(1) {
        ram = new uint8_t[8192];
}

MBC1::~MBC1() {
    delete[] ram;
}

uint8_t* MBC1::getExternalRAM() {
    return ram;
}

uint8_t* MBC1::getROMBank() {
    return romBanks[currentROMBank-1];
}

void MBC1::write(uint16_t address, uint8_t value) {
    if (address >= 0x2000 && address <= 0x3FFF) { // Lower 5 Bits of ROM Bank Number
        uint8_t lowerFiveBits = value & 0x1F;

        currentROMBank = (currentROMBank & 0xE0) | lowerFiveBits;
    } else if (address >= 0x4000 && address <= 0x5FFF) { // Upper 2 Bits of ROM Bank Number
        uint8_t upperTwoBits = value & 0x60;

        currentROMBank = (currentROMBank & 0x1F) | upperTwoBits;
    }

    if (currentROMBank == 0x00
        || currentROMBank == 0x20
        || currentROMBank == 0x40
        || currentROMBank == 0x60) {
        currentROMBank++;
    }
}
}<commit_msg>Fixed memory leak<commit_after>#include "mbc1.h"

namespace gameboy {
namespace mbc {
MBC1::MBC1(uint8_t **romBanks, uint8_t num) :
    romBanks(romBanks),
    numOfROMBanks(num),
    currentROMBank(1) {
        ram = new uint8_t[8192];
}

MBC1::~MBC1() {
    delete[] ram;
    
    for (int i = 0; i < numOfROMBanks; ++i) {
        delete[] romBanks[i];
    }
    delete[] romBanks;
}

uint8_t* MBC1::getExternalRAM() {
    return ram;
}

uint8_t* MBC1::getROMBank() {
    return romBanks[currentROMBank-1];
}

void MBC1::write(uint16_t address, uint8_t value) {
    if (address >= 0x2000 && address <= 0x3FFF) { // Lower 5 Bits of ROM Bank Number
        uint8_t lowerFiveBits = value & 0x1F;

        currentROMBank = (currentROMBank & 0xE0) | lowerFiveBits;
    } else if (address >= 0x4000 && address <= 0x5FFF) { // Upper 2 Bits of ROM Bank Number
        uint8_t upperTwoBits = value & 0x60;

        currentROMBank = (currentROMBank & 0x1F) | upperTwoBits;
    }

    if (currentROMBank == 0x00
        || currentROMBank == 0x20
        || currentROMBank == 0x40
        || currentROMBank == 0x60) {
        currentROMBank++;
    }
}
}
{'fraction_non_alphanumeric': 0.1289134438305709, 'fraction_numerical': 0.05662983425414365, 'mean_word_length': 2.887298747763864, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3186517', 'n_tokens_mistral': 910, 'n_tokens_neox': 809, 'n_words': 179}