mozilla/webvtt — pull request #86 by caitp (2013-02-12 06:29:12+00:00)
Title: webvtt_copy_string -- illogical behaviour

webvtt_copy_string does some weird things.

It dereferences the reference copied from 'right' rather than referencing it

It does not check that 'd' is valid, which it isn't always.

```C++
WEBVTT_EXPORT void
webvtt_copy_string( webvtt_string *left, const webvtt_string *right )
{
if( left ) {
webvtt_string_data *d = left->d;
if( right ) {
left->d = right->d;
} else {
left->d = &empty_string;
}
webvtt_deref( &left->d->refs );
if( webvtt_deref( &d->refs ) == 0 ) {
/**
* We don't try to check if we're freeing a static string or not.
* Static strings should be initialized with a reference count of '1',
* and should be ref'd or deref'd properly.
*
* If this is difficult, use the C++ bindings!
*/
webvtt_free( d );
}
}
}
```

This is code I wrote, so this is essentially just a reminder to myself to fix this :)