<commit_before>/* We are going to test whether create and close properly check their input. */

#include "test.h"

toku_rth* rth;

int main(int argc, const char *argv[]) {
    int r;
    parse_args(argc, argv);
    
    /* ********************************************************************** */

    rth = NULL;
    for (failon = 1; failon <= 2; failon++) {
        mallocced = 0;
        r = toku_rth_create(&rth, fail_malloc, toku_free, toku_realloc);
        CKERR2(r, ENOMEM);
        assert(rth==NULL);
    }
    r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    toku_rth_close(rth);
    rth = NULL;

    /* ********************************************************************** */

    size_t i;
    size_t iterations = 512 << 2;
    
    r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    for (i = 1; i < iterations; i++) {
        r = toku_rth_insert(rth, (TXNID)i);
        CKERR(r);
    }
    toku_rt_forest* f;
    for (i = 1; i < iterations; i++) {
        f = toku_rth_find(rth, (TXNID)i);
        assert(f);
    }
    f = toku_rth_find(rth, (TXNID)i);
    assert(!f);
    for (i = iterations - 1; i >= 1; i--) {
        toku_rth_delete(rth, (TXNID)i);
    }
    toku_rth_close(rth);
    rth = NULL;

    /* ********************************************************************** */

    r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    for (i = 1; i < iterations; i++) {
        r = toku_rth_insert(rth, (TXNID)i);
        CKERR(r);
    }
    for (i = 1; i < iterations; i++) {
        toku_rth_delete(rth, (TXNID)i);
    }
    toku_rth_close(rth);
    rth = NULL;

    /* ********************************************************************** */

    r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    for (i = iterations - 1; i >= 1; i--) {
        r = toku_rth_insert(rth, (TXNID)i);
        CKERR(r);
    }
    toku_rth_close(rth);
    rth = NULL;

    failon = 3;
    mallocced = 0;
    r = toku_rth_create(&rth, fail_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    r = toku_rth_insert(rth, (TXNID)1);
    CKERR2(r, ENOMEM);
    toku_rth_close(rth);
    rth = NULL;

    /* ********************************************************************** */

    r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    for (i = iterations - 1; i >= 1; i--) {
        r = toku_rth_insert(rth, (TXNID)i);
        CKERR(r);
    }
    toku_rth_clear(rth);
    assert(toku_rth_is_empty(rth));
    rth = NULL;

    return 0;
}<commit_msg>Addresses #567 Fixes memory leak (in a test)<commit_after>/* We are going to test whether create and close properly check their input. */

#include "test.h"

toku_rth* rth;

int main(int argc, const char *argv[]) {
    int r;
    parse_args(argc, argv);
    
    /* ********************************************************************** */

    rth = NULL;
    for (failon = 1; failon <= 2; failon++) {
        mallocced = 0;
        r = toku_rth_create(&rth, fail_malloc, toku_free, toku_realloc);
        CKERR2(r, ENOMEM);
        assert(rth==NULL);
    }
    r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    toku_rth_close(rth);
    rth = NULL;

    /* ********************************************************************** */

    size_t i;
    size_t iterations = 512 << 2;
    
    r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    for (i = 1; i < iterations; i++) {
        r = toku_rth_insert(rth, (TXNID)i);
        CKERR(r);
    }
    toku_rt_forest* f;
    for (i = 1; i < iterations; i++) {
        f = toku_rth_find(rth, (TXNID)i);
        assert(f);
    }
    f = toku_rth_find(rth, (TXNID)i);
    assert(!f);
    for (i = iterations - 1; i >= 1; i--) {
        toku_rth_delete(rth, (TXNID)i);
    }
    toku_rth_close(rth);
    rth = NULL;

    /* ********************************************************************** */

    r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    for (i = 1; i < iterations; i++) {
        r = toku_rth_insert(rth, (TXNID)i);
        CKERR(r);
    }
    for (i = 1; i < iterations; i++) {
        toku_rth_delete(rth, (TXNID)i);
    }
    toku_rth_close(rth);
    rth = NULL;

    /* ********************************************************************** */

    r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    for (i = iterations - 1; i >= 1; i--) {
        r = toku_rth_insert(rth, (TXNID)i);
        CKERR(r);
    }
    toku_rth_close(rth);
    rth = NULL;

    failon = 3;
    mallocced = 0;
    r = toku_rth_create(&rth, fail_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    r = toku_rth_insert(rth, (TXNID)1);
    CKERR2(r, ENOMEM);
    toku_rth_close(rth);
    rth = NULL;

    /* ********************************************************************** */

    r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(rth);
    for (i = iterations - 1; i >= 1; i--) {
        r = toku_rth_insert(rth, (TXNID)i);
        CKERR(r);
    }
    toku_rth_clear(rth);
    assert(toku_rth_is_empty(rth));
    toku_rth_close(rth);
    rth = NULL;

    return 0;
}
{'fraction_non_alphanumeric': 0.2644476956839795, 'fraction_numerical': 0.008961228968544257, 'mean_word_length': 2.805845511482255, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 9, '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': '1769900', 'n_tokens_mistral': 2230, 'n_tokens_neox': 2091, 'n_words': 406}