Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualkunos

Posted 03 December 2012 - 12:36 AM

Holy father of leakage.. what do we have here? Posted Image
My comments in bold, cause I am bald... no correction, they are in RED cause the code tag isn't bold enough to show bold.

  ~Widget()
  {
   cout << "children of node with value " << x << " being deleted" << endl;
   Node*sentinel = new Node;                 // WHOA?? new called in a destructor? for what?
   sentinel = list;                          // AH! That's why called new! To leak it one line later. Good job!
   cout << sentinel->data->x << "*" << endl;
   while (sentinel != NULL)
   {
	sentinel = sentinel->next;           // POTENTIALLY next is nullptr and if it is nullptr
	delete sentinel->prev;              // BAM, deferencing a null pointer... CRASH
   }
  }
  void RemoveAndDeleteAllWidgets()
  {
   //~Widget();
  }


So, a total mess in one function, I can't imagine what else you have around in your code.
If you are learning that's all fine.. take your time and crash the entire world until you get it right.
If you are in production, do yourself a favour and #include <vector> .

#2kunos

Posted 03 December 2012 - 12:35 AM

Holy father of leakage.. what do we have here? Posted Image
My comments in bold, cause I am bald... no correction, they are in RED cause the code tag isn't bold enough to show bold.

  ~Widget()
  {
   cout << "children of node with value " << x << " being deleted" << endl;
   Node*sentinel = new Node;[b] // WHOA?? new called in a destructor? for what?[/b]
   sentinel = list;  [b]// AH! That's why called new! To leak it one line later. Good job![/b] 
   cout << sentinel->data->x << "*" << endl;
   while (sentinel != NULL)
   {
	sentinel = sentinel->next; [b]// POTENTIALLY next is nullptr and if it is nullptr[/b]
	delete sentinel->prev;[b] // BAM, deferencing a null pointer... CRASH[/b]
   }
  }
  void RemoveAndDeleteAllWidgets()
  {
   //~Widget();
  }


So, a total mess in one function, I can't imagine what else you have around in your code.
If you are learning that's all fine.. take your time and crash the entire world until you get it right.
If you are in production, do yourself a favour and #include <vector> .

#1kunos

Posted 03 December 2012 - 12:34 AM

Holy father of leakage.. what do we have here? Posted Image
My comments in bold, cause I am bald.

  ~Widget()
  {
   cout << "children of node with value " << x << " being deleted" << endl;
   Node*sentinel = new Node;[b] // WHOA?? new called in a destructor? for what?[/b]
   sentinel = list;  [b]// AH! That's why called new! To leak it one line later. Good job![/b] 
   cout << sentinel->data->x << "*" << endl;
   while (sentinel != NULL)
   {
	sentinel = sentinel->next; [b]// POTENTIALLY next is nullptr and if it is nullptr[/b]
	delete sentinel->prev;[b] // BAM, deferencing a null pointer... CRASH[/b]
   }
  }
  void RemoveAndDeleteAllWidgets()
  {
   //~Widget();
  }


So, a total mess in one function, I can't imagine what else you have around in your code.
If you are learning that's all fine.. take your time and crash the entire world until you get it right.
If you are in production, do yourself a favour and #include <vector> .

PARTNERS