mirror of
https://github.com/m1k1o/neko.git
synced 2026-11-03 08:21:50 -06:00
fix(drop): free CString allocations and GFile refs in drag uri handling (#700)
Co-authored-by: hktitof <hktitof@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
b0f01cedea
commit
347418c3e7
@@ -82,12 +82,13 @@ char **dragUrisMake(int size) {
|
|||||||
void dragUrisSetFile(char **uris, char *file, int n) {
|
void dragUrisSetFile(char **uris, char *file, int n) {
|
||||||
GFile *gfile = g_file_new_for_path(file);
|
GFile *gfile = g_file_new_for_path(file);
|
||||||
uris[n] = g_file_get_uri(gfile);
|
uris[n] = g_file_get_uri(gfile);
|
||||||
|
g_object_unref(gfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dragUrisFree(char **uris, int size) {
|
void dragUrisFree(char **uris, int size) {
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
free(uris[i]);
|
g_free(uris[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(uris);
|
g_free(uris);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ package drop
|
|||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/kataras/go-events"
|
"github.com/kataras/go-events"
|
||||||
@@ -29,7 +31,9 @@ func OpenWindow(files []string) {
|
|||||||
defer C.dragUrisFree(urisUnsafe, size)
|
defer C.dragUrisFree(urisUnsafe, size)
|
||||||
|
|
||||||
for i, file := range files {
|
for i, file := range files {
|
||||||
C.dragUrisSetFile(urisUnsafe, C.CString(file), C.int(i))
|
cFile := C.CString(file)
|
||||||
|
C.dragUrisSetFile(urisUnsafe, cFile, C.int(i))
|
||||||
|
C.free(unsafe.Pointer(cFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
C.dragWindowOpen(urisUnsafe)
|
C.dragWindowOpen(urisUnsafe)
|
||||||
|
|||||||
Reference in New Issue
Block a user