Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML: X11 Window Class does not free X11 properly!  (Read 8986 times)

0 Members and 1 Guest are viewing this topic.

graphitemaster

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: yep and another one
« Reply #15 on: October 12, 2010, 01:21:09 pm »
Quote from: "Laurent"
Quote from: "graphitemaster"
yes in that same while loop, you need a
delete [] name; that's also not freeded

const GLubyte* name = reinterpret_cast<const GLubyte*>("glXCreateContextAttribsARB");

line 229,

http://sfml.svn.sourceforge.net/viewvc/sfml/branches/sfml2/src/SFML/Window/Linux/GlxContext.cpp?revision=1579&view=markup

String literals are not allocated dynamically, they don't need to be freed.

Maybe you should investigate a little bit more about the "leaks" that you report ;)


thats a byte which is a uchar* which does need to be freed, in this case it's being used to store memory, thus it has to be freed.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML: X11 Window Class does not free X11 properly!
« Reply #16 on: October 12, 2010, 01:23:10 pm »
Quote
thats a byte which is a uchar* which does need to be freed

No, it points to a variable that has automatic storage. It would have to be freed if it was allocated dynamically, the type of the variable has nothing to do with that.
Laurent Gomila - SFML developer

graphitemaster

  • Newbie
  • *
  • Posts: 18
    • View Profile
SFML: X11 Window Class does not free X11 properly!
« Reply #17 on: October 12, 2010, 01:26:07 pm »
my bad, I thought we were working with memory, Tank just reminded me that
glXCreateContextAttribsARB is a const literal, sorry Laurent

wilrader

  • Newbie
  • *
  • Posts: 5
    • View Profile
SFML: X11 Window Class does not free X11 properly!
« Reply #18 on: October 12, 2010, 08:14:45 pm »
graphitemaster: As I told Trina last night, the only time you really need to use free is when you have an associated new as well. Just because something has a pointer doesn't mean you always need to free it, which is what it appears that you are assuming.

Perhaps reading up on pointers and memory allocation/dynamic memory a little more might make things clearer.

I am, however, glad to see that your picking through the source code has uncovered a few bugs. :)

graphitemaster

  • Newbie
  • *
  • Posts: 18
    • View Profile
SFML: X11 Window Class does not free X11 properly!
« Reply #19 on: October 13, 2010, 07:53:12 am »
Quote from: "wilrader"
graphitemaster: As I told Trina last night, the only time you really need to use free is when you have an associated new as well. Just because something has a pointer doesn't mean you always need to free it, which is what it appears that you are assuming.

Perhaps reading up on pointers and memory allocation/dynamic memory a little more might make things clearer.

I am, however, glad to see that your picking through the source code has uncovered a few bugs. :)


You'll have to forgive me, I try to avoid pointers very much, only because they're the number one cause for memory leaks, and issues. Passing by reference is usually the smart thing to do in C++. However there is times when pointers are needed, and when then are, I usually code it to free it regardless of whether or not it should be. If she seg's then I give it a whirl in gdb where it usually tells me something like a double free, or free where there should not be, and I remove it.

the above may not always be a smart idea, but at least in the end I know everything I used has been freed properly, and we can all get on with our lifes, without worrying about memory leaks, which come and go. Please note some have come to me in the past and told me that the above was the dumbest idea that they have ever herd, I'm sorry it it is, but it was a trick that I was taught by from my teacher, and it has never failed me yet.

 

anything