haiku: Fix crash when opening window.
authorAdrien Destugues <pulkomandy@pulkomandy.tk>
Mon, 11 Nov 2019 22:14:00 -0500
changeset 132339dfa95a693ba
parent 13232 6058a0286a96
child 13234 c6c5c0c9ad2b
haiku: Fix crash when opening window.

- _num_clips was not set in constructor, so a NULL _clips could be
mistakenly dereferenced.
- As _clips is accessible outside the class, it is not a good idea to
free/reallocate it. Try to limit this by reallocating only when it needs to
grow.

Partially fixes Bugzilla #4442.
src/video/haiku/SDL_BWin.h
     1.1 --- a/src/video/haiku/SDL_BWin.h	Mon Nov 11 22:04:10 2019 -0500
     1.2 +++ b/src/video/haiku/SDL_BWin.h	Mon Nov 11 22:14:00 2019 -0500
     1.3 @@ -86,6 +86,7 @@
     1.4          _buffer_locker = new BLocker();
     1.5          _bitmap = NULL;
     1.6          _clips = NULL;
     1.7 +        _num_clips = 0;
     1.8  
     1.9  #ifdef DRAWTHREAD
    1.10          _draw_thread_id = spawn_thread(HAIKU_DrawThread, "drawing_thread",
    1.11 @@ -179,13 +180,17 @@
    1.12              _connected = true;
    1.13  
    1.14          case B_DIRECT_MODIFY:
    1.15 -            if(_clips) {
    1.16 -                free(_clips);
    1.17 -                _clips = NULL;
    1.18 +            if (info->clip_list_count > _num_clips)
    1.19 +            {
    1.20 +                if(_clips) {
    1.21 +                    free(_clips);
    1.22 +                    _clips = NULL;
    1.23 +                }
    1.24              }
    1.25  
    1.26              _num_clips = info->clip_list_count;
    1.27 -            _clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect));
    1.28 +            if (_clips == NULL)
    1.29 +                _clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect));
    1.30              if(_clips) {
    1.31                  memcpy(_clips, info->clip_list,
    1.32                      _num_clips*sizeof(clipping_rect));
    1.33 @@ -652,7 +657,7 @@
    1.34      clipping_rect   _bounds;
    1.35      BLocker        *_buffer_locker;
    1.36      clipping_rect  *_clips;
    1.37 -    int32           _num_clips;
    1.38 +    uint32          _num_clips;
    1.39      int32           _bytes_per_px;
    1.40      thread_id       _draw_thread_id;
    1.41