Skip to content

Commit

Permalink
Merge pull request #172 from ttencate/fix/geometry_from_wkt_leak
Browse files Browse the repository at this point in the history
Fix memory leak in Geometry::from_wkt
  • Loading branch information
jdroenner authored Mar 23, 2021
2 parents c62a306 + 5724f7f commit 9e5eda0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
`SpatialRef::axis_mapping_strategy` instead.
* Add support for reading and setting rasterband colour interpretations
* <https://github.com/georust/gdal/pull/144>
* Fixed memory leak in `Geometry::from_wkt`
* <https://github.com/georust/gdal/pull/172>

## 0.7.1
* fix docs.rs build for gdal-sys
* <https://github.com/georust/gdal/pull/128>
Expand Down
6 changes: 4 additions & 2 deletions src/vector/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::spatial_ref::{CoordTransform, SpatialRef};
use crate::utils::{_last_null_pointer_err, _string};
use gdal_sys::{self, OGRErr, OGRGeometryH, OGRwkbGeometryType};
use libc::{c_double, c_int, c_void};
use libc::{c_char, c_double, c_int, c_void};
use std::cell::RefCell;
use std::ffi::CString;
use std::fmt::{self, Debug};
Expand Down Expand Up @@ -75,7 +75,9 @@ impl Geometry {
/// [WKT](https://en.wikipedia.org/wiki/Well-known_text) string.
pub fn from_wkt(wkt: &str) -> Result<Geometry> {
let c_wkt = CString::new(wkt)?;
let mut c_wkt_ptr = c_wkt.into_raw();
// OGR_G_CreateFromWkt does not write to the pointed-to memory, but this is not reflected
// in its signature (`char**` instead of `char const**`), so we need a scary looking cast.
let mut c_wkt_ptr = c_wkt.as_ptr() as *mut c_char;
let mut c_geom = null_mut();
let rv = unsafe { gdal_sys::OGR_G_CreateFromWkt(&mut c_wkt_ptr, null_mut(), &mut c_geom) };
if rv != OGRErr::OGRERR_NONE {
Expand Down

0 comments on commit 9e5eda0

Please sign in to comment.