https://bugs.kde.org/show_bug.cgi?id=482137

--- Comment #11 from Marcel Hasler <mahas...@gmail.com> ---
(In reply to Fabio from comment #10)
> (In reply to Marcel Hasler from comment #9)
> > But here's a simple example to show that you cannot rely on the data 
> > remaining valid:
> 
> I know that when the local function variable goes out of scope it's not safe
> to use anymore.
> FreeRDP creates an internal duplicate of the "path" string using _strdup():
> 
> > if ((!isPath && !isSpecial) || !(drive->Path = _strdup(path)))
> 
> From that point FreeRDP will use its internal copy of the string stored in
> drive->Path.
> So, even if our variable gets deleted, it doesn't matter.

The point I was trying to make is that by the time freerdp actually calls
_strdup, both temporary QByteArray instances have already been destroyed and
the pointers are therefore no longer valid. It just *happens* to work because
the data hasn't yet been freed or reused/modified in the meantime, but that
doesn't mean the code is correct or that it will continue to work in the
future. The data just *happens* to still be available, but really you are
relying on undocumented behavior here. In fact, the Qt folks could modify their
internal implementation at any point (even from a patch version to the next),
causing your code to crash or misbehave in other ways.

As I see it, the solution is really simple here, just create two local
variables and avoid any potential trouble in the future.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to