summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2021-04-08 21:35:39 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2021-04-08 21:35:39 +0200
commitc3cfa64d2626d2a630cdc1c8fe6994f99baeec49 (patch)
tree22a7d3ac89c7269c7e1960b05317507b1ffc902c
parentb2f61deb37accb065480b591622415b9b9ff286e (diff)
wip
-rw-r--r--src/lib/eina/eina_promise.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/lib/eina/eina_promise.c b/src/lib/eina/eina_promise.c
index 4fe51206e4..d009a1aba9 100644
--- a/src/lib/eina/eina_promise.c
+++ b/src/lib/eina/eina_promise.c
@@ -1148,6 +1148,7 @@ typedef struct _Base_Ctx {
1148 Eina_Promise *promise; 1148 Eina_Promise *promise;
1149 Eina_Future **futures; 1149 Eina_Future **futures;
1150 unsigned int futures_len; 1150 unsigned int futures_len;
1151 unsigned char inside_free;
1151} Base_Ctx; 1152} Base_Ctx;
1152 1153
1153typedef struct _All_Promise_Ctx { 1154typedef struct _All_Promise_Ctx {
@@ -1161,21 +1162,30 @@ typedef struct _Race_Promise_Ctx {
1161 Eina_Bool dispatching; 1162 Eina_Bool dispatching;
1162} Race_Promise_Ctx; 1163} Race_Promise_Ctx;
1163 1164
1164static void 1165static short
1165_base_ctx_clean(Base_Ctx *ctx) 1166_base_ctx_clean(Base_Ctx *ctx)
1166{ 1167{
1167 unsigned int i; 1168 unsigned int i;
1168 for (i = 0; i < ctx->futures_len; i++) 1169
1170 ctx->inside_free++;
1171 for (i = 0; i < ctx->futures_len && ctx->futures; i++)
1169 if (ctx->futures[i]) _eina_future_cancel(ctx->futures[i], ECANCELED); 1172 if (ctx->futures[i]) _eina_future_cancel(ctx->futures[i], ECANCELED);
1170 free(ctx->futures); 1173 //prepare against double free
1174 Eina_Future **futures = ctx->futures;
1175 ctx->futures = NULL;
1176 if (futures)
1177 free(futures);
1178 ctx->inside_free--;
1179 return ctx->inside_free;
1171} 1180}
1172 1181
1173static void 1182static void
1174_all_promise_ctx_free(All_Promise_Ctx *ctx) 1183_all_promise_ctx_free(All_Promise_Ctx *ctx)
1175{ 1184{
1176 _base_ctx_clean(&ctx->base); 1185 int depth = _base_ctx_clean(&ctx->base);
1177 eina_value_flush(&ctx->values); 1186 eina_value_flush(&ctx->values);
1178 free(ctx); 1187 if (depth == 0)
1188 free(ctx);
1179} 1189}
1180 1190
1181static void 1191static void
@@ -1187,8 +1197,9 @@ _all_promise_cancel(void *data, const Eina_Promise *dead EINA_UNUSED)
1187static void 1197static void
1188_race_promise_ctx_free(Race_Promise_Ctx *ctx) 1198_race_promise_ctx_free(Race_Promise_Ctx *ctx)
1189{ 1199{
1190 _base_ctx_clean(&ctx->base); 1200 int depth = _base_ctx_clean(&ctx->base);
1191 free(ctx); 1201 if (depth == 0)
1202 free(ctx);
1192} 1203}
1193 1204
1194static void 1205static void