Fix memory leak with image drag and drop

Dragging an image from the file selector into the sequencer
was leaking memory.

Regression in b5d778a7d4.
This commit is contained in:
Campbell Barton 2021-01-13 16:09:53 +11:00
parent 5d99199880
commit 37c5552742
2 changed files with 10 additions and 1 deletions

View File

@ -1993,7 +1993,12 @@ static bool ui_but_drag_init(bContext *C,
}
else {
wmDrag *drag = WM_event_start_drag(
C, but->icon, but->dragtype, but->dragpoin, ui_but_value_get(but), WM_DRAG_NOP);
C,
but->icon,
but->dragtype,
but->dragpoin,
ui_but_value_get(but),
(but->dragflag & UI_BUT_DRAGPOIN_FREE) ? WM_DRAG_FREE_DATA : WM_DRAG_NOP);
/* wmDrag has ownership over dragpoin now, stop messing with it. */
but->dragpoin = NULL;

View File

@ -150,6 +150,10 @@ wmDrag *WM_event_start_drag(
switch (type) {
case WM_DRAG_PATH:
BLI_strncpy(drag->path, poin, FILE_MAX);
/* As the path is being copied, free it immediately as `drag` wont "own" the data. */
if (flags & WM_DRAG_FREE_DATA) {
MEM_freeN(poin);
}
break;
case WM_DRAG_ID:
if (poin) {