aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2023-10-29 12:59:45 +0800
committerPo Lu2023-10-29 12:59:45 +0800
commit59a3edc3559057e6f0346e3f1b3b13e8ef3e1683 (patch)
treee39dd5ff3ea5fd4096035b7d71b6e4ebf138abf3 /java
parent3624e9bd409075d4f78b240ebdb356f93fd9c3e4 (diff)
downloademacs-59a3edc3559057e6f0346e3f1b3b13e8ef3e1683.tar.gz
emacs-59a3edc3559057e6f0346e3f1b3b13e8ef3e1683.zip
Avert a crash and file descriptor leak in yank-media
* java/org/gnu/emacs/EmacsNative.java (close): New declaration. * java/org/gnu/emacs/EmacsSdk11Clipboard.java (getClipboardData): Catch SecurityException and guarantee file descriptors are closed even if exceptions arise. * src/android.c (dup): Export another function.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsNative.java3
-rw-r--r--java/org/gnu/emacs/EmacsSdk11Clipboard.java24
2 files changed, 27 insertions, 0 deletions
diff --git a/java/org/gnu/emacs/EmacsNative.java b/java/org/gnu/emacs/EmacsNative.java
index 7d7e1e5d831..f15927bb3a7 100644
--- a/java/org/gnu/emacs/EmacsNative.java
+++ b/java/org/gnu/emacs/EmacsNative.java
@@ -39,6 +39,9 @@ public final class EmacsNative
39 /* Like `dup' in C. */ 39 /* Like `dup' in C. */
40 public static native int dup (int fd); 40 public static native int dup (int fd);
41 41
42 /* Like `close' in C. */
43 public static native int close (int fd);
44
42 /* Obtain the fingerprint of this build of Emacs. The fingerprint 45 /* Obtain the fingerprint of this build of Emacs. The fingerprint
43 can be used to determine the dump file name. */ 46 can be used to determine the dump file name. */
44 public static native String getFingerprint (); 47 public static native String getFingerprint ();
diff --git a/java/org/gnu/emacs/EmacsSdk11Clipboard.java b/java/org/gnu/emacs/EmacsSdk11Clipboard.java
index b8a43496b6d..b068a89831e 100644
--- a/java/org/gnu/emacs/EmacsSdk11Clipboard.java
+++ b/java/org/gnu/emacs/EmacsSdk11Clipboard.java
@@ -245,6 +245,8 @@ public final class EmacsSdk11Clipboard extends EmacsClipboard
245 if (data == null || data.getItemCount () < 1) 245 if (data == null || data.getItemCount () < 1)
246 return null; 246 return null;
247 247
248 fd = -1;
249
248 try 250 try
249 { 251 {
250 uri = data.getItemAt (0).getUri (); 252 uri = data.getItemAt (0).getUri ();
@@ -267,12 +269,34 @@ public final class EmacsSdk11Clipboard extends EmacsClipboard
267 /* Close the original offset. */ 269 /* Close the original offset. */
268 assetFd.close (); 270 assetFd.close ();
269 } 271 }
272 catch (SecurityException e)
273 {
274 /* Guarantee a file descriptor duplicated or detached is
275 ultimately closed if an error arises. */
276
277 if (fd != -1)
278 EmacsNative.close (fd);
279
280 return null;
281 }
270 catch (FileNotFoundException e) 282 catch (FileNotFoundException e)
271 { 283 {
284 /* Guarantee a file descriptor duplicated or detached is
285 ultimately closed if an error arises. */
286
287 if (fd != -1)
288 EmacsNative.close (fd);
289
272 return null; 290 return null;
273 } 291 }
274 catch (IOException e) 292 catch (IOException e)
275 { 293 {
294 /* Guarantee a file descriptor duplicated or detached is
295 ultimately closed if an error arises. */
296
297 if (fd != -1)
298 EmacsNative.close (fd);
299
276 return null; 300 return null;
277 } 301 }
278 302