Skip to content

Commit

Permalink
fix segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
MXWXZ committed May 30, 2024
1 parent 7cf8798 commit 780b885
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.1.4
## Bug fix
1. Fix segmentation fault when shared API is enabled.

# 0.1.3
## Bug fix
1. Fix login db error when using PostgreSQL.
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
restart: always
depends_on:
- redis
- db
volumes:
- ./plugin/:/app/plugin
- ./assets/_plugin/:/app/assets/_plugin
Expand Down
7 changes: 7 additions & 0 deletions skynet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ pub struct Skynet {
pub shared_api: HashMap<HyUuid, Box<dyn Any + Send + Sync>>,
}

impl Drop for Skynet {
fn drop(&mut self) {
// clear API first otherwise SIGSEGV.
self.shared_api.clear();
}
}

impl Skynet {
#[allow(clippy::missing_panics_doc)]
pub fn insert_menu(&mut self, item: MenuItem, pos: usize, parent: Option<HyUuid>) -> bool {
Expand Down
15 changes: 13 additions & 2 deletions skynet/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ pub struct PluginInstance {
library: Option<Library>,
}

impl Drop for PluginInstance {
fn drop(&mut self) {
self.instance = None;
self.library = None;
}
}

impl PluginInstance {
/// Get setting name.
#[must_use]
Expand Down Expand Up @@ -293,7 +300,11 @@ impl PluginManager {
let dll = dll.pop().unwrap_or_default();
let inst = Self::load_internal(path.as_ref().join(PLUGIN_CONFIG), dll)?;
if let Some(x) = self.get(&inst.id) {
bail!(PluginError::ConflictID(x.id, inst.name, x.name.clone()));
bail!(PluginError::ConflictID(
x.id,
inst.name.clone(),
x.name.clone()
));
}
skynet.setting.set(db, &inst.setting_name(), "0").await?;
let mut wlock = self.plugin.write();
Expand Down Expand Up @@ -385,7 +396,7 @@ impl PluginManager {
if let Some(x) = conflict_id.get(&obj.id) {
panic!(
"{}",
PluginError::ConflictID(obj.id, obj.name, x.to_owned())
PluginError::ConflictID(obj.id, obj.name.clone(), x.to_owned())
);
}
conflict_id.insert(obj.id, obj.name.clone());
Expand Down

0 comments on commit 780b885

Please sign in to comment.