# Macro crashes when closing the file after saving the trees with 'double free or corruption (out)' message

**URL:** <https://root-forum.cern.ch/t/macro-crashes-when-closing-the-file-after-saving-the-trees-with-double-free-or-corruption-out-message/56973>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [November 2, 2023, 4:56pm UTC](https://root-forum.cern.ch/t/macro-crashes-when-closing-the-file-after-saving-the-trees-with-double-free-or-corruption-out-message/56973 "2023-11-02T16:56:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elemental](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/elemental/32/34841_2.png) [@elemental](https://root-forum.cern.ch/u/elemental)\
**Post date:** [November 2, 2023, 4:56pm UTC](https://root-forum.cern.ch/t/macro-crashes-when-closing-the-file-after-saving-the-trees-with-double-free-or-corruption-out-message/56973/1 "2023-11-02T16:56:56Z")

</div>

I am trying to fill a tree with branches with user-defined class-objects. When I am finished writing the file with the tree as in ‘t\_cands-\>Write()’, save the file as ‘outfile -\>Save();’ and then close the file as ‘outfile -\>Close();’, I get the following error and the macro crashes:

double free or corruption (out)

I don’t understand the meaning of the error or the cause. It happens just when I try to close the file in the macro.

Any help in identifying the error would be much appreciated as I am new to root.

_ROOT Version:_ 6.28/06  
_Platform:_ macOS Sonomo 14.0  
_Compiler:_ clang-1500.0.40.1

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [November 2, 2023, 5:32pm UTC](https://root-forum.cern.ch/t/macro-crashes-when-closing-the-file-after-saving-the-trees-with-double-free-or-corruption-out-message/56973/2 "2023-11-02T17:32:15Z")

</div>

What is the stack trace of the error? Do you delete the `tree` or `histograms` after the call the `Close` (which actually should be better to be a class to `delete outfile`

---

<div class="post-metadata">

**Author:** ![elemental](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/elemental/32/34841_2.png) [@elemental](https://root-forum.cern.ch/u/elemental)\
**Post date:** [November 11, 2023, 12:03pm UTC](https://root-forum.cern.ch/t/macro-crashes-when-closing-the-file-after-saving-the-trees-with-double-free-or-corruption-out-message/56973/3 "2023-11-11T12:03:05Z")

</div>

Hi @pcanal,  
Thanks for helping out.  
I delete the file as you pointed out. `delete outfile`  
This is all the message I get before the macro crashes out of root. No stack trace as such
