Skip to content

Temporary files are not cleared #11

@tibetiroka

Description

@tibetiroka

NativeLibraryLoader.java creates a temporary directory NATIVES_DIR, and extracts the Luau native library files there. However, there is no shutdown hook or deleteOnExit() call for any of these files, so they remain after the JVM terminates. This either pollutes the filesystem, or leaks memory (if the temporary files are in-memory, as is usually the case with /tmp on linux).

Solving it should be as simple as:

--- src/main/java/net/hollowcube/luau/util/NativeLibraryLoader.java
+++ src/main/java/net/hollowcube/luau/util/NativeLibraryLoader.java
@@ -20,8 +20,9 @@
 
     static {
         try {
             NATIVES_DIR = Files.createTempDirectory("luau-natives");
+            NATIVES_DIR.deleteOnExit();
         } catch (IOException e) {
             throw new RuntimeException(
                 "Failed to create temporary directory for native libraries",
                 e
@@ -44,8 +45,9 @@
             System.mapLibraryName(name)
         );
         try (InputStream in = innerPath.openStream()) {
             Files.copy(in, targetPath);
+            targetPath.toFile().deleteOnExit();
             System.load(targetPath.toString());
             return true;
         } catch (IOException e) {
             return false;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions