]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix libselinux object leaks
authorPo Lu <luangruo@yahoo.com>
Sun, 20 Aug 2023 04:46:33 +0000 (12:46 +0800)
committerPo Lu <luangruo@yahoo.com>
Sun, 20 Aug 2023 04:48:03 +0000 (12:48 +0800)
* src/fileio.c (Fcopy_file, Fset_file_selinux_context): Call
freecon prior to signaling file errors.

src/fileio.c

index fc9b04678f5e81bf80d2d0b3da846d678e74baea..51e3e8849d150b0f1071f657ebeb8ef07f3100b1 100644 (file)
@@ -2496,6 +2496,8 @@ permissions.  */)
     {
       /* Set the modified context back to the file.  */
       bool fail = fsetfilecon (ofd, con) != 0;
+      freecon (con);
+
       /* See https://debbugs.gnu.org/11245 for ENOTSUP.  */
       if (fail
 #if defined HAVE_ANDROID && !defined ANDROID_STUBIFY
@@ -2506,8 +2508,6 @@ permissions.  */)
 #endif /* defined HAVE_ANDROID && !defined ANDROID_STUBIFY */
          && errno != ENOTSUP)
        report_file_error ("Doing fsetfilecon", newname);
-
-      freecon (con);
     }
 #endif
 
@@ -3510,12 +3510,12 @@ or if Emacs was not compiled with SELinux support.  */)
          fail = (lsetfilecon (SSDATA (encoded_absname),
                               context_str (parsed_con))
                  != 0);
+         context_free (parsed_con);
+         freecon (con);
+
           /* See https://debbugs.gnu.org/11245 for ENOTSUP.  */
          if (fail && errno != ENOTSUP)
            report_file_error ("Doing lsetfilecon", absname);
-
-         context_free (parsed_con);
-         freecon (con);
          return fail ? Qnil : Qt;
        }
       else