mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 23:16:30 +03:00
Closure shouldn't copy qr variable into it's own scope and we should
never return null pointer
This commit is contained in:
@@ -49,7 +49,7 @@ pub unsafe fn dc_get_securejoin_qr(
|
||||
}
|
||||
let self_addr = context.sql.get_config(context, "configured_addr");
|
||||
|
||||
let cleanup = |fingerprint| {
|
||||
let cleanup = |fingerprint, qr: Option<String>| {
|
||||
free(fingerprint as *mut libc::c_void);
|
||||
free(invitenumber as *mut libc::c_void);
|
||||
free(auth as *mut libc::c_void);
|
||||
@@ -57,13 +57,13 @@ pub unsafe fn dc_get_securejoin_qr(
|
||||
if let Some(qr) = qr {
|
||||
qr.strdup()
|
||||
} else {
|
||||
std::ptr::null_mut()
|
||||
"".strdup()
|
||||
}
|
||||
};
|
||||
|
||||
if self_addr.is_none() {
|
||||
error!(context, 0, "Not configured, cannot generate QR code.",);
|
||||
return cleanup(fingerprint);
|
||||
return cleanup(fingerprint, qr);
|
||||
}
|
||||
|
||||
let self_addr = self_addr.unwrap();
|
||||
@@ -75,7 +75,7 @@ pub unsafe fn dc_get_securejoin_qr(
|
||||
fingerprint = get_self_fingerprint(context);
|
||||
|
||||
if fingerprint.is_null() {
|
||||
return cleanup(fingerprint);
|
||||
return cleanup(fingerprint, qr);
|
||||
}
|
||||
|
||||
let self_addr_urlencoded = utf8_percent_encode(&self_addr, NON_ALPHANUMERIC).to_string();
|
||||
@@ -101,7 +101,7 @@ pub unsafe fn dc_get_securejoin_qr(
|
||||
context,
|
||||
0, "Cannot get QR-code for chat-id {}", group_chat_id,
|
||||
);
|
||||
return cleanup(fingerprint);
|
||||
return cleanup(fingerprint, None);
|
||||
}
|
||||
} else {
|
||||
Some(format!(
|
||||
@@ -116,7 +116,7 @@ pub unsafe fn dc_get_securejoin_qr(
|
||||
|
||||
info!(context, 0, "Generated QR code: {}", qr.as_ref().unwrap());
|
||||
|
||||
cleanup(fingerprint)
|
||||
cleanup(fingerprint, qr)
|
||||
}
|
||||
|
||||
fn get_self_fingerprint(context: &Context) -> *mut libc::c_char {
|
||||
|
||||
Reference in New Issue
Block a user