Skip to content

Commit deaac67

Browse files
author
roman
committed
ln2 test BUGFIX ln2 test setup memory leak
1 parent 1920cd5 commit deaac67

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

tests/ln2_test.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,9 @@ int
9797
ln2_glob_test_setup(struct ln2_test_ctx **test_ctx)
9898
{
9999
int ret;
100-
struct ln2_test_ctx *tmp_ctx;
101100

102-
*test_ctx = NULL;
103-
104-
tmp_ctx = calloc(1, sizeof *tmp_ctx);
105-
if (!tmp_ctx) {
101+
*test_ctx = calloc(1, sizeof **test_ctx);
102+
if (!*test_ctx) {
106103
ret = 1;
107104
goto cleanup;
108105
}
@@ -123,29 +120,27 @@ ln2_glob_test_setup(struct ln2_test_ctx **test_ctx)
123120
}
124121

125122
/* init barrier */
126-
ret = pthread_barrier_init(&tmp_ctx->barrier, NULL, 2);
123+
ret = pthread_barrier_init(&(*test_ctx)->barrier, NULL, 2);
127124
if (ret) {
128125
goto cleanup;
129126
}
130127

131128
/* create libyang context */
132-
ret = ly_ctx_new(MODULES_DIR, 0, &tmp_ctx->ctx);
129+
ret = ly_ctx_new(MODULES_DIR, 0, &(*test_ctx)->ctx);
133130
if (ret) {
134131
goto cleanup;
135132
}
136133

137134
/* load default yang modules */
138-
ret = nc_server_init_ctx(&tmp_ctx->ctx);
135+
ret = nc_server_init_ctx(&(*test_ctx)->ctx);
139136
if (ret) {
140137
goto cleanup;
141138
}
142-
ret = nc_server_config_load_modules(&tmp_ctx->ctx);
139+
ret = nc_server_config_load_modules(&(*test_ctx)->ctx);
143140
if (ret) {
144141
goto cleanup;
145142
}
146143

147-
*test_ctx = tmp_ctx;
148-
149144
cleanup:
150145
return ret;
151146
}

0 commit comments

Comments
 (0)