Re: [i3] [PATCH] Improved i3bar hide mode behavior (In my point of view)

  • From: Mateusz Loskot <mateusz@xxxxxxxxxx>
  • To: "Discussions/Questions about the i3 window manager" <i3-discuss@xxxxxxxxxxxxx>
  • Date: Thu, 26 Jul 2012 12:26:37 +0100

On 26 July 2012 12:14, Michael Stapelberg <michael@xxxxxxxx> wrote:

Quoting Mateusz Loskot (2012-07-13 20:06:58)
1) You are not using FREE(last_urgent_ws);, but free(last_urgent_ws) in
line 1489, which is unsafe (it is not guaranteed that last_urgent_ws
is != NULL).

There is no such guarantee needed for free() as per the C99 Standard:

7.20.3.2 The free function
2 The free function causes the space pointed to by ptr to be
deallocated, that is, made
available for further allocation. If ptr is a null pointer, no action occurs.
I think you misunderstood me. What FREE does is it sets the pointer to
NULL after calling free(). Therefore, the following code works fine:

FREE(last_urgent_ws);
// …things happen here, and much later:
FREE(last_urgent_ws);

While the following is not:

free(last_urgent_ws);
// …things happen here, and much later:
free(last_urgent_ws); // points to an old memory location

Michael,

Yes, it looks I confused things.
You're perfectly right here.

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net

Other related posts: