Unmap needle before returning from main after failed haystack maps. The process return value is still `PROG_RET_MAP_HAYSTACK_FAILED`, but a warning message is printed if unmapping the needle failed after the rollback. (this is unlikely)

Fortune for naka's current commit: Half curse − 半凶
master
Avril 3 years ago
parent 05b96a7e1b
commit 037a234953
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -137,6 +137,7 @@ inv_args:
else if(!argv[2])
goto inv_args;
int m_rval =0;
map_t needle;
INFO("Mapping needle file `%s'", argv[1]);
if(!map_handle_err(map_file(argv[1], false, 0, 0, &needle))) return PROG_RET_MAP_NEEDLE_FAILED;
@ -148,7 +149,11 @@ inv_args:
usize hsn = AS(argc-2, usize);
map_t haystacks[hsn];
TRACE("Attempting to map %lu haystacks", hsn);
if(!map_haystacks((const char**)(argv+1), haystacks)) return PROG_RET_MAP_HAYSTACK_FAILED;
if(!map_haystacks((const char**)(argv+1), haystacks)) {
// Unmap needle before return.
if(!map_handle_err(map_free(needle))) WARN("Failed to unmap needle before exiting after failed haystack maps");
return PROG_RET_MAP_HAYSTACK_FAILED;
}
#ifdef _FEATURE_PARALLEL // Multi-threaded
TODO("Multithreaded processing currently unimplemented.");
@ -170,7 +175,6 @@ inv_args:
free(full_result);
#endif
int m_rval =0;
for(int i=0;i<(int)hsn;i++) {
INFO("Unmapping haystack haystack file `%s' (#%d) (map addr %p)", argv[i+1], i+1, haystacks+i);
if(!map_handle_err(map_free(haystacks[i]))) m_rval = !m_rval ? PROG_RET_UNMAP_HAYSTACK_N_FAILED(i+1) : m_rval;

Loading…
Cancel
Save