-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid memory leak in router in case of bind parameter errors
- Loading branch information
Showing
3 changed files
with
61 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//! Memory-safe wrapper around the FFI binding to Query. | ||
use pgdog_plugin::Query; | ||
use std::{ | ||
ffi::CString, | ||
ops::{Deref, DerefMut}, | ||
}; | ||
|
||
use super::Error; | ||
|
||
/// Memory-safe wrapper around the FFI binding to Query. | ||
pub struct Request { | ||
query: Query, | ||
} | ||
|
||
impl Deref for Request { | ||
type Target = Query; | ||
fn deref(&self) -> &Self::Target { | ||
&self.query | ||
} | ||
} | ||
|
||
impl DerefMut for Request { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.query | ||
} | ||
} | ||
|
||
impl Request { | ||
/// New query request. | ||
pub fn new(query: &str) -> Result<Self, Error> { | ||
Ok(Self { | ||
query: Query::new(CString::new(query.as_bytes())?), | ||
}) | ||
} | ||
|
||
/// Get constructed query. | ||
pub fn query(&self) -> Query { | ||
self.query | ||
} | ||
} | ||
|
||
impl Drop for Request { | ||
fn drop(&mut self) { | ||
unsafe { self.query.drop() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters