@@ -55,6 +55,14 @@ bool retro_vfs_init_saf(JNIEnv *(*get_jni_env)(void), jobject activity_object)
5555 if (env == NULL )
5656 return false;
5757
58+ (* env )-> PushLocalFrame (env , 14 );
59+ if ((* env )-> ExceptionOccurred (env ))
60+ {
61+ (* env )-> ExceptionDescribe (env );
62+ (* env )-> ExceptionClear (env );
63+ return false;
64+ }
65+
5866 vfs_saf_content_resolver_object = NULL ;
5967 vfs_saf_vfs_implementation_saf_class = NULL ;
6068 vfs_saf_saf_stat_class = NULL ;
@@ -172,6 +180,7 @@ bool retro_vfs_init_saf(JNIEnv *(*get_jni_env)(void), jobject activity_object)
172180 }
173181
174182 vfs_saf_get_jni_env = get_jni_env ;
183+ (* env )-> PopLocalFrame (env , NULL );
175184 return true;
176185
177186error :
@@ -201,6 +210,7 @@ bool retro_vfs_init_saf(JNIEnv *(*get_jni_env)(void), jobject activity_object)
201210 vfs_saf_saf_directory_class = NULL ;
202211 if ((* env )-> ExceptionOccurred (env )) goto error ;
203212 }
213+ (* env )-> PopLocalFrame (env , NULL );
204214 return false;
205215}
206216
@@ -376,6 +386,14 @@ int retro_vfs_file_open_saf(const char *tree, const char *path, unsigned mode)
376386 if (env == NULL )
377387 return -1 ;
378388
389+ (* env )-> PushLocalFrame (env , 2 );
390+ if ((* env )-> ExceptionOccurred (env ))
391+ {
392+ (* env )-> ExceptionDescribe (env );
393+ (* env )-> ExceptionClear (env );
394+ return -1 ;
395+ }
396+
379397 tree_object = (* env )-> NewStringUTF (env , tree );
380398 if ((* env )-> ExceptionOccurred (env )) goto error ;
381399
@@ -385,11 +403,13 @@ int retro_vfs_file_open_saf(const char *tree, const char *path, unsigned mode)
385403 fd = (* env )-> CallStaticIntMethod (env , vfs_saf_vfs_implementation_saf_class , vfs_saf_open_saf_file_method , vfs_saf_content_resolver_object , tree_object , path_object , !!(mode & RETRO_VFS_FILE_ACCESS_READ ), !!(mode & RETRO_VFS_FILE_ACCESS_WRITE ), !(mode & RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING ));
386404 if ((* env )-> ExceptionOccurred (env )) goto error ;
387405
406+ (* env )-> PopLocalFrame (env , NULL );
388407 return fd ;
389408
390409error :
391410 (* env )-> ExceptionDescribe (env );
392411 (* env )-> ExceptionClear (env );
412+ (* env )-> PopLocalFrame (env , NULL );
393413 return -1 ;
394414}
395415
@@ -406,6 +426,14 @@ int retro_vfs_file_remove_saf(const char *tree, const char *path)
406426 if (env == NULL )
407427 return -1 ;
408428
429+ (* env )-> PushLocalFrame (env , 2 );
430+ if ((* env )-> ExceptionOccurred (env ))
431+ {
432+ (* env )-> ExceptionDescribe (env );
433+ (* env )-> ExceptionClear (env );
434+ return -1 ;
435+ }
436+
409437 tree_object = (* env )-> NewStringUTF (env , tree );
410438 if ((* env )-> ExceptionOccurred (env )) goto error ;
411439
@@ -415,11 +443,13 @@ int retro_vfs_file_remove_saf(const char *tree, const char *path)
415443 ret = (* env )-> CallStaticBooleanMethod (env , vfs_saf_vfs_implementation_saf_class , vfs_saf_remove_saf_file_method , vfs_saf_content_resolver_object , tree_object , path_object );
416444 if ((* env )-> ExceptionOccurred (env )) goto error ;
417445
446+ (* env )-> PopLocalFrame (env , NULL );
418447 return ret ? 0 : -1 ;
419448
420449error :
421450 (* env )-> ExceptionDescribe (env );
422451 (* env )-> ExceptionClear (env );
452+ (* env )-> PopLocalFrame (env , NULL );
423453 return -1 ;
424454}
425455
@@ -443,6 +473,14 @@ int retro_vfs_stat_saf(const char *tree, const char *path, int32_t *size)
443473 if (env == NULL )
444474 return 0 ;
445475
476+ (* env )-> PushLocalFrame (env , 3 );
477+ if ((* env )-> ExceptionOccurred (env ))
478+ {
479+ (* env )-> ExceptionDescribe (env );
480+ (* env )-> ExceptionClear (env );
481+ return 0 ;
482+ }
483+
446484 tree_object = (* env )-> NewStringUTF (env , tree );
447485 if ((* env )-> ExceptionOccurred (env )) goto error ;
448486
@@ -457,14 +495,20 @@ int retro_vfs_stat_saf(const char *tree, const char *path, int32_t *size)
457495 saf_stat_size = (* env )-> CallLongMethod (env , saf_stat , vfs_saf_saf_stat_get_size_method );
458496 if ((* env )-> ExceptionOccurred (env )) goto error ;
459497 if (saf_stat_size < 0 )
498+ {
499+ (* env )-> PopLocalFrame (env , NULL );
460500 return 0 ;
501+ }
461502 }
462503 else
463504 {
464505 bool saf_stat_is_open = (* env )-> CallBooleanMethod (env , saf_stat , vfs_saf_saf_stat_get_is_open_method );
465506 if ((* env )-> ExceptionOccurred (env )) goto error ;
466507 if (!saf_stat_is_open )
508+ {
509+ (* env )-> PopLocalFrame (env , NULL );
467510 return 0 ;
511+ }
468512 }
469513
470514 saf_stat_is_directory = (* env )-> CallBooleanMethod (env , saf_stat , vfs_saf_saf_stat_get_is_directory_method );
@@ -473,11 +517,13 @@ int retro_vfs_stat_saf(const char *tree, const char *path, int32_t *size)
473517 if (size != NULL )
474518 * size = saf_stat_size > INT32_MAX ? INT32_MAX : (int32_t )saf_stat_size ;
475519
520+ (* env )-> PopLocalFrame (env , NULL );
476521 return saf_stat_is_directory ? RETRO_VFS_STAT_IS_VALID | RETRO_VFS_STAT_IS_DIRECTORY : RETRO_VFS_STAT_IS_VALID ;
477522
478523error :
479524 (* env )-> ExceptionDescribe (env );
480525 (* env )-> ExceptionClear (env );
526+ (* env )-> PopLocalFrame (env , NULL );
481527 return 0 ;
482528}
483529
@@ -494,6 +540,14 @@ int retro_vfs_mkdir_saf(const char *tree, const char *dir)
494540 if (env == NULL )
495541 return -1 ;
496542
543+ (* env )-> PushLocalFrame (env , 2 );
544+ if ((* env )-> ExceptionOccurred (env ))
545+ {
546+ (* env )-> ExceptionDescribe (env );
547+ (* env )-> ExceptionClear (env );
548+ return -1 ;
549+ }
550+
497551 tree_object = (* env )-> NewStringUTF (env , tree );
498552 if ((* env )-> ExceptionOccurred (env )) goto error ;
499553
@@ -503,11 +557,13 @@ int retro_vfs_mkdir_saf(const char *tree, const char *dir)
503557 ret = (* env )-> CallStaticIntMethod (env , vfs_saf_vfs_implementation_saf_class , vfs_saf_mkdir_saf_method , vfs_saf_content_resolver_object , tree_object , path_object );
504558 if ((* env )-> ExceptionOccurred (env )) goto error ;
505559
560+ (* env )-> PopLocalFrame (env , NULL );
506561 return ret ;
507562
508563error :
509564 (* env )-> ExceptionDescribe (env );
510565 (* env )-> ExceptionClear (env );
566+ (* env )-> PopLocalFrame (env , NULL );
511567 return -1 ;
512568}
513569
@@ -528,6 +584,15 @@ libretro_vfs_implementation_saf_dir *retro_vfs_opendir_saf(const char *tree, con
528584 if (dirstream == NULL )
529585 return NULL ;
530586
587+ (* env )-> PushLocalFrame (env , 2 );
588+ if ((* env )-> ExceptionOccurred (env ))
589+ {
590+ free (dirstream );
591+ (* env )-> ExceptionDescribe (env );
592+ (* env )-> ExceptionClear (env );
593+ return NULL ;
594+ }
595+
531596 tree_object = (* env )-> NewStringUTF (env , tree );
532597 if ((* env )-> ExceptionOccurred (env )) goto error ;
533598
@@ -543,12 +608,14 @@ libretro_vfs_implementation_saf_dir *retro_vfs_opendir_saf(const char *tree, con
543608 dirstream -> dirent_name_object = NULL ;
544609 dirstream -> dirent_name = NULL ;
545610 dirstream -> dirent_is_dir = false;
611+ (* env )-> PopLocalFrame (env , NULL );
546612 return dirstream ;
547613
548614error :
549615 free (dirstream );
550616 (* env )-> ExceptionDescribe (env );
551617 (* env )-> ExceptionClear (env );
618+ (* env )-> PopLocalFrame (env , NULL );
552619 return NULL ;
553620}
554621
@@ -565,6 +632,14 @@ bool retro_vfs_readdir_saf(libretro_vfs_implementation_saf_dir *dirstream)
565632 if (env == NULL )
566633 return false;
567634
635+ (* env )-> PushLocalFrame (env , 1 );
636+ if ((* env )-> ExceptionOccurred (env ))
637+ {
638+ (* env )-> ExceptionDescribe (env );
639+ (* env )-> ExceptionClear (env );
640+ return false;
641+ }
642+
568643 ret = (* env )-> CallBooleanMethod (env , dirstream -> directory_object , vfs_saf_saf_directory_readdir_method );
569644 if ((* env )-> ExceptionOccurred (env )) goto error ;
570645
@@ -584,6 +659,7 @@ bool retro_vfs_readdir_saf(libretro_vfs_implementation_saf_dir *dirstream)
584659 if (!ret )
585660 {
586661 dirstream -> dirent_is_dir = false;
662+ (* env )-> PopLocalFrame (env , NULL );
587663 return false;
588664 }
589665
@@ -601,6 +677,7 @@ bool retro_vfs_readdir_saf(libretro_vfs_implementation_saf_dir *dirstream)
601677 if ((* env )-> ExceptionOccurred (env )) goto error ;
602678 dirstream -> dirent_name = dirent_name ;
603679
680+ (* env )-> PopLocalFrame (env , NULL );
604681 return true;
605682
606683error :
@@ -619,6 +696,7 @@ bool retro_vfs_readdir_saf(libretro_vfs_implementation_saf_dir *dirstream)
619696 if ((* env )-> ExceptionOccurred (env )) goto error ;
620697 }
621698 dirstream -> dirent_is_dir = false;
699+ (* env )-> PopLocalFrame (env , NULL );
622700 return false;
623701}
624702
0 commit comments