Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't leak temporary file during test and inital loading of lib. #141

Merged
merged 3 commits into from
Feb 1, 2022

Conversation

normanmaurer
Copy link
Member

Motivation:

We did leak a file during our tests and also during the initial loading of the native lib

Modifications:

Use a tempory file / directory and so ensure the file is deleted

Result:

No leaked file

Motivation:

We did leak a file during our tests and also during the initial loading of the native lib

Modifications:

Use a tempory file / directory and so ensure the file is deleted

Result:

No leaked file
@normanmaurer normanmaurer added this to the 0.0.13.Final milestone Feb 1, 2022
@normanmaurer normanmaurer merged commit 60f7b89 into main Feb 1, 2022
@chrisvest chrisvest deleted the tmp_file branch February 1, 2022 18:41
try {
// First, try calling a side-effect free JNI method to see if the library was already
// loaded by the application.
Native.createFile();
Native.createFile(tmpFile.toString());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "side-effect free" but creating a file is not. How did we get here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this returns a file descriptor that isn't closed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side-effect free in terms of JNI.

static jint netty_create_file(JNIEnv *env, jclass class, jstring filename) {
const char *file = (*env)->GetStringUTFChars(env, filename, 0);

int fd = open(file, O_RDWR | O_TRUNC | O_CREAT, 0644);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're Linux specific (because io_uring) we can use O_TMPFILE and have the "file" refer to the parent directory. That way the file will never have a name, and will vanish once the fd is closed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point ... let me do this

Copy link
Contributor

@franz1981 franz1981 Feb 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good idea but seems requires some checks to be sure it works

_TMPFILE requires support by the underlying filesystem;
              only a subset of Linux filesystems provide that support.
              In the initial implementation, support was provided in the
              ext2, ext3, ext4, UDF, Minix, and tmpfs filesystems.
              Support for other filesystems has subsequently been added
              as follows: XFS (Linux 3.15); Btrfs (Linux 3.16); F2FS
              (Linux 3.16); and ubifs (Linux 4.9)

but it seems vastly supported TBH

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@franz1981 thanks a lot! Because of this I just did not change anything but added a explicit delete to the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants