Skip to content

Commit 7ac2d2c

Browse files
committed
Fix deadlock in default handler
1 parent 892c8d5 commit 7ac2d2c

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/libumf.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,16 @@ umf_result_t umfCtlGet(const char *name, void *ctx, void *arg, size_t size) {
103103
if (name == NULL || arg == NULL) {
104104
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
105105
}
106-
// using ctx is disallowed for default settings
107-
if (ctx && strstr(name, ".default.")) {
108-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
109-
}
110106
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_READ,
111-
arg, size)
112-
? UMF_RESULT_ERROR_UNKNOWN
113-
: UMF_RESULT_SUCCESS;
107+
arg, size);
114108
}
115109

116110
umf_result_t umfCtlSet(const char *name, void *ctx, void *arg, size_t size) {
117111
// Context can be NULL when setting defaults
118112
if (name == NULL || arg == NULL || size == 0) {
119113
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
120114
}
121-
// using ctx is disallowed for default settings
122-
if (ctx && strstr(name, ".default.")) {
123-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
124-
}
115+
125116
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_WRITE,
126117
arg, size)
127118
? UMF_RESULT_ERROR_UNKNOWN

src/memory_pool.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ static int CTL_SUBTREE_HANDLER(default)(void *ctx,
5757
(void)indexes, (void)source, (void)ctx;
5858
utils_init_once(&mem_pool_ctl_initialized, ctl_init);
5959
utils_mutex_lock(&ctl_mtx);
60+
61+
// using ctx is disallowed for default settings
62+
if (ctx && strstr(extra_name, "default")) {
63+
utils_mutex_unlock(&ctl_mtx);
64+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
65+
}
66+
6067
if (queryType == CTL_QUERY_WRITE) {
6168
int i = 0;
6269
for (; i < UMF_DEFAULT_SIZE; i++) {
@@ -69,6 +76,7 @@ static int CTL_SUBTREE_HANDLER(default)(void *ctx,
6976
}
7077
if (UMF_DEFAULT_SIZE == i) {
7178
LOG_ERR("Default entries array is full");
79+
utils_mutex_unlock(&ctl_mtx);
7280
return UMF_RESULT_ERROR_OUT_OF_RESOURCES;
7381
}
7482
} else if (queryType == CTL_QUERY_READ) {
@@ -81,6 +89,7 @@ static int CTL_SUBTREE_HANDLER(default)(void *ctx,
8189
}
8290
if (UMF_DEFAULT_SIZE == i) {
8391
LOG_WARN("Wrong path name: %s", extra_name);
92+
utils_mutex_unlock(&ctl_mtx);
8493
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
8594
}
8695
}

src/pool/pool_disjoint.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ umf_result_t disjoint_pool_ctl(void *hPool, int operationType, const char *name,
7575
(void)operationType, (void)queryType;
7676
utils_init_once(&ctl_initialized, initialize_disjoint_ctl);
7777

78-
return ctl_query(&disjoint_ctl_root, hPool, CTL_QUERY_PROGRAMMATIC,
79-
name, queryType, arg, size);
78+
return ctl_query(&disjoint_ctl_root, hPool, CTL_QUERY_PROGRAMMATIC, name,
79+
queryType, arg, size);
8080
}
8181

8282
// Temporary solution for disabling memory poisoning. This is needed because

0 commit comments

Comments
 (0)