Skip to content

Commit

Permalink
train : fix ggerganov#4227 (double free in examples/train-text-from-s…
Browse files Browse the repository at this point in the history
…cratch/train-text-from-scratch.cpp) (ggerganov#4351)

On commit b1108 (44c117f) xaedes added

    ggml_allocr * alloc = NULL;

    ... (many lines in between)

    if (alloc) {
        ggml_allocr_free(alloc);
    }

Which is correct, but it's easy to lose context after many lines in between.

On commit b1287 (0e76a899) xaedes made a big change. From here on, alloc is freed eagerly.

    alloc = ggml_allocr_new(...)
    ... (short lines of code)
    ggml_allocr_free(alloc)

This happens a few times, but alloc is never set to NULL, and many lines below,
we still have

    if (alloc) {
        ggml_allocr_free(alloc);
    }

which causes a double-free.
  • Loading branch information
casavaca authored Dec 7, 2023
1 parent 05cd6e5 commit 81bc921
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions examples/train-text-from-scratch/train-text-from-scratch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1295,10 +1295,6 @@ int main(int argc, char ** argv) {
opt_cb_data.last_save_iter = opt->iter;
}

if (alloc) {
ggml_allocr_free(alloc);
}

ggml_free(opt->ctx);
free_train_state(train);
ggml_free(model.ctx);
Expand Down

0 comments on commit 81bc921

Please sign in to comment.