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

Segmentation fault when DataSet::close is called #423

Closed
nms-scribe opened this issue Jul 12, 2023 · 5 comments
Closed

Segmentation fault when DataSet::close is called #423

nms-scribe opened this issue Jul 12, 2023 · 5 comments

Comments

@nms-scribe
Copy link

My program is stopping with a segmentation fault after calling close on a dataset.

Here's my test code:

#[test]
fn open_gdal_layer() {
    use std::path::PathBuf;
    use gdal::Dataset;


    let mut ds = Dataset::open(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("sample_data").join("wisconsin.tif")).expect("Dataset should have opened.");
    ds.close().expect("Should have closed"); // Get a segmentation fault if this is called, I don't know why.


}

The output:

cargo test                   
    Finished test [unoptimized + debuginfo] target(s) in 0.03s
     Running unittests src/main.rs (target/debug/deps/nfmt-86223208dc86738c)

running 1 test
error: test failed, to rerun pass `--bin nfmt`

Caused by:
  process didn't exit successfully: `/home/neil/Projects/fantasy-map-tools/target/debug/deps/nfmt-86223208dc86738c` (signal: 11, SIGSEGV: invalid memory reference)

I'm running this on Arch Linux. Here's the gdal version struct. Is 3.6.3 too new and do I need to downgrade?

GDALVersionInfo {
    RELEASE_NAME: "3.6.3"
    RELEASE_DATE: "20230307"
    VERSION_NUM: "3060300"
    BUILD_INFO {
        OGR_ENABLED: "YES"
        PAM_ENABLED: "YES"
        GEOS_ENABLED: "YES"
        GEOS_VERSION: "3.11.1-CAPI-1.17.1"
        PROJ_BUILD_VERSION: "9.1.1"
        PROJ_RUNTIME_VERSION: "9.2.0"
        COMPILER: "GCC 12.2.1 20230201"
    }
}

I'm not getting my 'expect' message for closing, so I assume the seg fault is happening after that. My guess is that the functionality of close is being repeated by the dataset's implementation of Drop, and that's where the fault is happening.

If this is the case, why would I ever want to call 'close'?

@lnicola
Copy link
Member

lnicola commented Jul 12, 2023

Yeah, sorry for that: #420. Please don't use it in the meanwhile.

@lnicola
Copy link
Member

lnicola commented Jul 12, 2023

I think it exist so you can get notified of errors that occur while writing the data. It's pretty much not idiomatic to have close methods in Rust, and you can call flush_cache manually, I suppose.

@lnicola
Copy link
Member

lnicola commented Jul 12, 2023

See also https://github.com/rouault/gdal/blob/rfc91_text/doc/source/development/rfc/rfc91_dataset_close.rst. Flushing the cache isn't enough to make sure you're not going to silently lose errors.

@nms-scribe
Copy link
Author

Okay, thank you.

@lnicola lnicola closed this as completed Aug 18, 2023
@lnicola
Copy link
Member

lnicola commented Aug 24, 2023

https://crates.io/crates/gdal/0.16.0 is now available. Sorry for the inconvenience.

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

No branches or pull requests

2 participants