Skip to content

Commit 50286dc

Browse files
committed
free the memory of clap after parsing options
- --nofile is now only existed in *nix build except Android
1 parent 468207e commit 50286dc

File tree

7 files changed

+782
-737
lines changed

7 files changed

+782
-737
lines changed

bin/sslocal.rs

Lines changed: 330 additions & 318 deletions
Large diffs are not rendered by default.

bin/ssmanager.rs

Lines changed: 211 additions & 199 deletions
Large diffs are not rendered by default.

bin/ssserver.rs

Lines changed: 227 additions & 215 deletions
Large diffs are not rendered by default.

crates/shadowsocks-service/src/config.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ struct SSConfig {
123123
mode: Option<String>,
124124
#[serde(skip_serializing_if = "Option::is_none")]
125125
no_delay: Option<bool>,
126+
#[cfg(all(unix, not(target_os = "android")))]
126127
#[serde(skip_serializing_if = "Option::is_none")]
127128
nofile: Option<u64>,
128129
#[serde(skip_serializing_if = "Option::is_none")]
@@ -718,6 +719,7 @@ pub struct Config {
718719
/// Set `TCP_NODELAY` socket option
719720
pub no_delay: bool,
720721
/// `RLIMIT_NOFILE` option for *nix systems
722+
#[cfg(all(unix, not(target_os = "android")))]
721723
pub nofile: Option<u64>,
722724

723725
/// Set `SO_MARK` socket option for outbound sockets
@@ -829,6 +831,7 @@ impl Config {
829831
ipv6_first: false,
830832

831833
no_delay: false,
834+
#[cfg(all(unix, not(target_os = "android")))]
832835
nofile: None,
833836

834837
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -1282,7 +1285,10 @@ impl Config {
12821285
nconfig.udp_max_associations = config.udp_max_associations;
12831286

12841287
// RLIMIT_NOFILE
1285-
nconfig.nofile = config.nofile;
1288+
#[cfg(all(unix, not(target_os = "android")))]
1289+
{
1290+
nconfig.nofile = config.nofile;
1291+
}
12861292

12871293
// Uses IPv6 first
12881294
if let Some(f) = config.ipv6_first {
@@ -1774,7 +1780,10 @@ impl fmt::Display for Config {
17741780

17751781
jconf.udp_max_associations = self.udp_max_associations;
17761782

1777-
jconf.nofile = self.nofile;
1783+
#[cfg(all(unix, not(target_os = "android")))]
1784+
{
1785+
jconf.nofile = self.nofile;
1786+
}
17781787

17791788
if self.ipv6_first {
17801789
jconf.ipv6_first = Some(self.ipv6_first);

crates/shadowsocks-service/src/local/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub async fn run(mut config: Config) -> io::Result<()> {
5858
}
5959
}
6060

61-
#[cfg(unix)]
61+
#[cfg(all(unix, not(target_os = "android")))]
6262
if let Some(nofile) = config.nofile {
6363
use crate::sys::set_nofile;
6464
if let Err(err) = set_nofile(nofile) {

crates/shadowsocks-service/src/manager/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub async fn run(config: Config) -> io::Result<()> {
2222

2323
trace!("{:?}", config);
2424

25-
#[cfg(unix)]
25+
#[cfg(all(unix, not(target_os = "android")))]
2626
if let Some(nofile) = config.nofile {
2727
use crate::sys::set_nofile;
2828
if let Err(err) = set_nofile(nofile) {

crates/shadowsocks-service/src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub async fn run(config: Config) -> io::Result<()> {
3434
}
3535
}
3636

37-
#[cfg(unix)]
37+
#[cfg(all(unix, not(target_os = "android")))]
3838
if let Some(nofile) = config.nofile {
3939
use crate::sys::set_nofile;
4040
if let Err(err) = set_nofile(nofile) {

0 commit comments

Comments
 (0)