Browse Source

Prevent memory leaks

Creating an owned String takes time and space in the heap and should be
done lazily. But in some places error message (which is an owned String)
is created even if there's no errors.
master
Alexey Yerin 4 years ago committed by Garrit Franke
parent
commit
38933ba333
  1. 4
      src/main.rs

4
src/main.rs

@ -158,12 +158,12 @@ fn handle_client(mut stream: TlsStream<TcpStream>, static_root: &str) -> Result<
let index_path = path
.join("index.gmi")
.to_str()
.ok_or("invalid Unicode".to_owned())?
.ok_or_else(|| "invalid Unicode".to_owned())?
.to_owned();
write_file(&index_path)?.send(stream)
} else {
write_file(path.to_str().ok_or("invalid Unicode".to_owned())?)?.send(stream)
write_file(path.to_str().ok_or_else(|| "invalid Unicode".to_owned())?)?.send(stream)
}
} else {
GeminiResponse::not_found().send(stream)

Loading…
Cancel
Save