MCPcopy Create free account
hub / github.com/CodeSentryAI/lockbud / detect_instance

Method detect_instance

src/detector/memory/use_after_free.rs:55–75  ·  view source on GitHub ↗
(
        &self,
        instance: &Instance<'tcx>,
        alias_analysis: &mut AliasAnalysis<'_, 'tcx>,
        manual_drops: &[(Location, Place<'tcx>)],
    )

Source from the content-addressed store, hash-verified

53 }
54
55 fn detect_instance(
56 &self,
57 instance: &Instance<'tcx>,
58 alias_analysis: &mut AliasAnalysis<'_, 'tcx>,
59 manual_drops: &[(Location, Place<'tcx>)],
60 ) -> Vec<Report> {
61 let mut diagnosis_set = FxHashSet::default();
62 let body = self.tcx.instance_mir(instance.def);
63 let raw_ptrs = self.collect_raw_ptrs(body);
64 if raw_ptrs.is_empty() {
65 return vec![];
66 }
67 let drops = self.collect_drops(body, manual_drops);
68 let pts = alias_analysis.get_or_insert_pts(instance.def_id(), body);
69 diagnosis_set.extend(detect_escape_to_global(pts, &drops, body, self.tcx));
70 diagnosis_set.extend(detect_escape_to_return_or_param(
71 pts, &drops, body, self.tcx,
72 ));
73 diagnosis_set.extend(detect_use_after_drop(&raw_ptrs, pts, &drops, body));
74 diagnosis_set.into_iter().map(|diagnosis| Report::UseAfterFree(ReportContent::new("UseAfterFree".to_owned(), "Possibly".to_owned(), diagnosis, "Raw ptr is used or escapes the current function after the pointed value is dropped".to_owned()))).collect::<Vec<_>>()
75 }
76
77 fn collect_raw_ptrs(&self, body: &Body<'tcx>) -> FxHashSet<Local> {
78 body.local_decls

Callers 1

detectMethod · 0.80

Calls 6

detect_escape_to_globalFunction · 0.85
detect_use_after_dropFunction · 0.85
collect_raw_ptrsMethod · 0.80
collect_dropsMethod · 0.80
get_or_insert_ptsMethod · 0.80

Tested by

no test coverage detected