Skip to content

Commit 4bf5ad0

Browse files
committed
sdl: events: Fix DropEvent memory leak #274
1 parent 6e06b4f commit 4bf5ad0

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

sdl/events.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,18 @@ type cDollarGestureEvent C.SDL_DollarGestureEvent
386386
// DropEvent contains an event used to request a file open by the system.
387387
// (https://wiki.libsdl.org/SDL_DropEvent)
388388
type DropEvent struct {
389-
Type uint32 // DROPFILE, DROPTEXT, DROPBEGIN, DROPCOMPLETE
390-
Timestamp uint32 // timestamp of the event
391-
File unsafe.Pointer // the file name
392-
WindowID uint32 // the window that was dropped on, if any
389+
Type uint32 // DROPFILE, DROPTEXT, DROPBEGIN, DROPCOMPLETE
390+
Timestamp uint32 // timestamp of the event
391+
File string // the file name
392+
WindowID uint32 // the window that was dropped on, if any
393+
}
394+
395+
type cDropEvent struct {
396+
Type uint32
397+
Timestamp uint32
398+
File unsafe.Pointer
399+
WindowID uint32
393400
}
394-
type cDropEvent C.SDL_DropEvent
395401

396402
// RenderEvent contains render event information.
397403
// (https://wiki.libsdl.org/SDL_EventType)
@@ -576,7 +582,10 @@ func goEvent(cevent *CEvent) Event {
576582
case MULTIGESTURE:
577583
return (*MultiGestureEvent)(unsafe.Pointer(cevent))
578584
case DROPFILE:
579-
return (*DropEvent)(unsafe.Pointer(cevent))
585+
e := (*cDropEvent)(unsafe.Pointer(cevent))
586+
event := DropEvent{Type: e.Type, Timestamp: e.Timestamp, File: string(C.GoString((*C.char)(e.File))), WindowID: e.WindowID}
587+
C.SDL_free(e.File)
588+
return &event
580589
case RENDER_TARGETS_RESET:
581590
return (*RenderEvent)(unsafe.Pointer(cevent))
582591
case QUIT:

0 commit comments

Comments
 (0)