Skip to content

Commit 8f5a4e6

Browse files
authored
Merge pull request apache#713 from apache/hotfix/coverity-fix
[CID 335557]Fix use-after-free in http_admin
2 parents ab7b7af + 9a5602f commit 8f5a4e6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

bundles/http_admin/http_admin/src/websocket_admin.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "websocket_admin.h"
2828

2929
#include "celix_compiler.h"
30+
#include "celix_stdlib_cleanup.h"
3031
#include "celix_utils_api.h"
3132

3233
struct websocket_admin_manager {
@@ -41,7 +42,7 @@ struct websocket_admin_manager {
4142
websocket_admin_manager_t *websocketAdmin_create(celix_bundle_context_t *context, struct mg_context *svr_ctx) {
4243
celix_status_t status;
4344

44-
websocket_admin_manager_t *admin = (websocket_admin_manager_t *) calloc(1, sizeof(websocket_admin_manager_t));
45+
celix_autofree websocket_admin_manager_t *admin = (websocket_admin_manager_t *) calloc(1, sizeof(websocket_admin_manager_t));
4546

4647
if (admin == NULL) {
4748
return NULL;
@@ -53,10 +54,10 @@ websocket_admin_manager_t *websocketAdmin_create(celix_bundle_context_t *context
5354

5455
if(status != CELIX_SUCCESS) {
5556
//No need to destroy other things
56-
free(admin);
57+
return NULL;
5758
}
5859

59-
return admin;
60+
return celix_steal_ptr(admin);
6061
}
6162

6263
void websocketAdmin_destroy(websocket_admin_manager_t *admin) {

0 commit comments

Comments
 (0)