title: C++ / cygwin_exception::open_stackdumpfile: Dumping stack trace to *.exe.stackdump
body: <p>I get cygwin_exception::open_stackdumpfile: Dumping stack trace to *.exe.stackdump error trying to run my code. It is a simple implementation of BST trees and the error appears when I execute delete function.
  Here is my code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;cstddef&gt;
  
  using namespace std;
  
  /*
   * BST Trees
   */
  
  struct BST_node {
      int key;
      BST_node *left, *right;
  };
  
  BST_node * BST_search(BST_node *node, int key) {
      //search node with given key
      if (node == NULL)
          return NULL;
      if (node-&gt;key == key)
          return node;
      if (node-&gt;key &gt; key)
          return BST_search(node-&gt;left, key);
      else
          return BST_search(node-&gt;right, key);
  }
  
  bool key_in_tree(BST_node *root, int key) {
      return BST_search(root, key) != NULL;
  }
  
  BST_node * BST_insert(BST_node *node, int key) {
      if (!key_in_tree(node, key)) {
          if (node == NULL) {
              BST_node *tmp = new BST_node;
              tmp-&gt;key = key;
              tmp-&gt;left = tmp-&gt;right = NULL;
              return tmp;
          }
  
          if (key &lt; node-&gt;key)
              node-&gt;left = BST_insert(node-&gt;left, key);
          else
              node-&gt;right = BST_insert(node-&gt;right, key);
          return node;
      }
  }
  
  BST_node * BST_find_parent(BST_node * node, BST_node * root) {
      //find node's parent
      if (root-&gt;left == node || root-&gt;right == node) {
          return root;
      } else {
          if (root-&gt;left != NULL)
              return BST_find_parent(node, root-&gt;left);
          if (root-&gt;right != NULL)
              return BST_find_parent(node, root-&gt;right);
      }
  
  }
  
  BST_node * BST_find_max(BST_node * node) {
      if (node-&gt;right != NULL)
          return BST_find_max(node-&gt;right);
      else
          return node;
  }
  
  void BST_delete(BST_node * node, int key) {
      //delete node with given key, node - root of the tree
      BST_node * node_to_remove = BST_search(node, key);
      BST_node * parent = BST_find_parent(node_to_remove, node);
  
      if (node_to_remove != NULL) {
  
          //if node doesn't have children - delete
          if (node_to_remove-&gt;left == NULL &amp;&amp; node_to_remove-&gt;right == NULL) {
              //set null in parent
              if (parent-&gt;left == node_to_remove)
                  parent-&gt;left = NULL;
              else
                  parent-&gt;right = NULL;
          }
  
          //node to remove has one child 
          if (node_to_remove-&gt;left == NULL &amp;&amp; node_to_remove-&gt;right != NULL) {
              if (parent-&gt;left == node_to_remove)
                  parent-&gt;left = node_to_remove-&gt;right;
              else
                  parent-&gt;right = node_to_remove-&gt;right;
          }
  
          if (node_to_remove-&gt;left != NULL &amp;&amp; node_to_remove-&gt;right == NULL) {
              if (parent-&gt;left == node_to_remove){
                  parent-&gt;left = node_to_remove-&gt;left;
              }
              else{
                  parent-&gt;right = node_to_remove-&gt;left;
              }
          }
  
          //replace with biggest node in left subtree
          if (node_to_remove-&gt;left != NULL &amp;&amp; node_to_remove-&gt;right != NULL) {
              BST_node * node_to_change = BST_find_max(node_to_remove-&gt;left);
              int tmp = node_to_change-&gt;key;
              BST_delete(node, tmp);
              node_to_remove-&gt;key = tmp;
          }
      }
  }
  
  int main(int argc, char** argv) {
      BST_node *root = NULL;
      root = BST_insert(root, 10);
      root = BST_insert(root, 8);
      root = BST_insert(root, 9);
      root = BST_insert(root, 5);
      root = BST_insert(root, 7);
      root = BST_insert(root, 100);
      root = BST_insert(root, 87);
      BST_delete(root, 100);
      return 0;
  }
  </code></pre>
  
  <p>The error I get looks like this:
  27 [main] bst 4828 cygwin_exception::open_stackdumpfile: Dumping stack trace to bst.exe.stackdump</p>