Guard prof_active reset by opt_prof

Set `prof_active` to read-only when `opt_prof` is turned off.
This commit is contained in:
Yinan Zhang
2019-08-27 14:42:14 -07:00
parent 1df9dd3515
commit beb7c16e94
4 changed files with 49 additions and 2 deletions

View File

@@ -2662,7 +2662,8 @@ prof_active_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
bool oldval;
if (!config_prof) {
return ENOENT;
ret = ENOENT;
goto label_return;
}
if (newp != NULL) {
@@ -2670,7 +2671,12 @@ prof_active_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
ret = EINVAL;
goto label_return;
}
oldval = prof_active_set(tsd_tsdn(tsd), *(bool *)newp);
bool val = *(bool *)newp;
if (!opt_prof && val) {
ret = ENOENT;
goto label_return;
}
oldval = prof_active_set(tsd_tsdn(tsd), val);
} else {
oldval = prof_active_get(tsd_tsdn(tsd));
}

View File

@@ -788,6 +788,7 @@ bool
prof_active_get(tsdn_t *tsdn) {
bool prof_active_current;
prof_active_assert();
malloc_mutex_lock(tsdn, &prof_active_mtx);
prof_active_current = prof_active;
malloc_mutex_unlock(tsdn, &prof_active_mtx);
@@ -798,10 +799,12 @@ bool
prof_active_set(tsdn_t *tsdn, bool active) {
bool prof_active_old;
prof_active_assert();
malloc_mutex_lock(tsdn, &prof_active_mtx);
prof_active_old = prof_active;
prof_active = active;
malloc_mutex_unlock(tsdn, &prof_active_mtx);
prof_active_assert();
return prof_active_old;
}