Prevent returning from main without unmapping all haystacks+needle on haystack unmap failure.

Main return value is either: 0 (success), PROG_RET_UNMAP_HAYSTACK_N_FAILED(n) for first haystack unmap failure, PROG_RET_UNMAP_NEEDLE_FAILED if haystacks unmapped okay (m_rval was previsouly 0). (After `m_rval` is set to non-zero, it keeps that value even if subsequent errors accumulate.)

Fortune for naka's current commit: Small blessing − 小吉
master
Avril 3 years ago
parent 2ce5037725
commit 05b96a7e1b
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -170,13 +170,15 @@ 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]))) return PROG_RET_UNMAP_HAYSTACK_N_FAILED(i+1);
if(!map_handle_err(map_free(haystacks[i]))) m_rval = !m_rval ? PROG_RET_UNMAP_HAYSTACK_N_FAILED(i+1) : m_rval;
}
TRACE("Unmap haystacks ended with main rval: %d", m_rval);
INFO("Unmapping needle file `%s'", *argv);
if(!map_handle_err(map_free(needle))) return PROG_RET_UNMAP_NEEDLE_FAILED;
TRACE("main end");
return 0;
if(!map_handle_err(map_free(needle))) m_rval = !m_rval ? PROG_RET_UNMAP_NEEDLE_FAILED : m_rval;
TRACE("main end: rval %d", m_rval);
return m_rval;
}

Loading…
Cancel
Save