about summary refs log tree commit diff
path: root/parrot_module/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'parrot_module/src/lib.rs')
-rw-r--r--parrot_module/src/lib.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/parrot_module/src/lib.rs b/parrot_module/src/lib.rs
index 148f41d..38148ae 100644
--- a/parrot_module/src/lib.rs
+++ b/parrot_module/src/lib.rs
@@ -21,7 +21,7 @@ const HEADERS: &'static [[*const ffi::c_char; 2]] =
 	&[[c"Content-Type".as_ptr(), c"text/plain".as_ptr()]];
 
 #[unsafe(no_mangle)]
-extern "C" fn handle(req: *const ModuleRequest) -> *const ModuleResponse {
+extern "C" fn cgi_handle(req: *const ModuleRequest) -> *const ModuleResponse {
 	let mut ret = String::new();
 
 	// unwrap is bad here
@@ -31,7 +31,14 @@ extern "C" fn handle(req: *const ModuleRequest) -> *const ModuleResponse {
 		let kvarr = reqref.headers[idx as usize];
 		let k = unsafe { CStr::from_ptr(kvarr[0]) }.to_string_lossy();
 		let v = unsafe { CStr::from_ptr(kvarr[1]) }.to_string_lossy();
-		ret.push_str(&format!("{k}: {v}\n"));
+
+		// While debugging I removed the format!() because it was SIGSEGVing
+		// as the String it allocated freed, and now that this is here it can stay
+		ret.push_str(&k);
+		ret.push(':');
+		ret.push(' ');
+		ret.push_str(&v);
+		ret.push('\n')
 	}
 
 	let body = CString::new(ret).unwrap();
@@ -45,13 +52,16 @@ extern "C" fn handle(req: *const ModuleRequest) -> *const ModuleResponse {
 	};
 
 	let boxed = Box::new(resp);
-
 	Box::<ModuleResponse>::into_raw(boxed)
 }
 
 #[unsafe(no_mangle)]
-extern "C" fn free(req: *const ModuleResponse) {
+extern "C" fn cgi_cleanup(req: *const ModuleResponse) {
 	// from_raw what we need to here so that these get dropped
 	let boxed = unsafe { Box::from_raw(req as *mut ModuleResponse) };
 	let body = unsafe { CString::from_raw(boxed.body as *mut i8) };
+
+	// Explicitly calling drop here to feel good about myself
+	drop(body);
+	drop(boxed);
 }