Patch: Fix KEncodingProber crashiness
Peter Oberndorfer
kumbayo84 at arcor.de
Fri Mar 20 20:16:53 GMT 2009
On Freitag 20 März 2009, Jeff Mitchell wrote:
> KEncodingProber likes to crash. I'm guessing no one is really using this
> code outside of us (and we just started), but it has some glaring issues:
>
> 1) Memory is allocated to a const char * by using strdup, but is removed by
> using delete, not free.
>
> 2) Memory is always allocated on the heap to the const char * in the
> constructor, but this memory is not freed before overwriting it with a new
> value, leading to a (miniscule) memory leak.
>
> 3) Largest problem: in the function unicodeTest, there are assignments from
> string literals, but later in the destructor there is a delete call (which
> is what is sparking the crash). When the string literal is being assigned,
> the string itself isn't being copied, but rather the address of the string
> literal is being copied. The literal itself exists in the executable, not
> on the heap, so trying to delete it is likely to cause bad things to happen
> (and is probably the source of the crashes we are seeing).
>
4)
currentConfidence is set when unicodeTest detects something.
But the value is never used.
So confidence 0.0 is returned i think?
5)
I think the prober is leaked on setProberType()?
6)
uselesss #define MINIMUM_THRESHOLD ?
> This patch does the following:
>
> *Replaces the const char * pointer with a QString on the stack for safety.
> *Replaces a strdup call with a QByteArray and a .data() call, which is not
> strictly necessary but ensures that any safety checks in QByteArray are
> handled.
>
> I'd like to put it in trunk and backport it for 4.2.2.
>
> Thanks,
> Jeff
>
>
Greetings Peter
More information about the kde-core-devel
mailing list