Skip to content

Commit

Permalink
sdl: events: Fix DropEvent memory leak #274
Browse files Browse the repository at this point in the history
  • Loading branch information
malashin committed Nov 8, 2017
1 parent 6e06b4f commit 4bf5ad0
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions sdl/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,18 @@ type cDollarGestureEvent C.SDL_DollarGestureEvent
// DropEvent contains an event used to request a file open by the system.
// (https://wiki.libsdl.org/SDL_DropEvent)
type DropEvent struct {
Type uint32 // DROPFILE, DROPTEXT, DROPBEGIN, DROPCOMPLETE
Timestamp uint32 // timestamp of the event
File unsafe.Pointer // the file name
WindowID uint32 // the window that was dropped on, if any
Type uint32 // DROPFILE, DROPTEXT, DROPBEGIN, DROPCOMPLETE
Timestamp uint32 // timestamp of the event
File string // the file name
WindowID uint32 // the window that was dropped on, if any
}

type cDropEvent struct {
Type uint32
Timestamp uint32
File unsafe.Pointer
WindowID uint32
}
type cDropEvent C.SDL_DropEvent

// RenderEvent contains render event information.
// (https://wiki.libsdl.org/SDL_EventType)
Expand Down Expand Up @@ -576,7 +582,10 @@ func goEvent(cevent *CEvent) Event {
case MULTIGESTURE:
return (*MultiGestureEvent)(unsafe.Pointer(cevent))
case DROPFILE:
return (*DropEvent)(unsafe.Pointer(cevent))
e := (*cDropEvent)(unsafe.Pointer(cevent))
event := DropEvent{Type: e.Type, Timestamp: e.Timestamp, File: string(C.GoString((*C.char)(e.File))), WindowID: e.WindowID}
C.SDL_free(e.File)
return &event
case RENDER_TARGETS_RESET:
return (*RenderEvent)(unsafe.Pointer(cevent))
case QUIT:
Expand Down

0 comments on commit 4bf5ad0

Please sign in to comment.