Mark an object as freed in the auto release queue, so that users can still * free things manually if they want. * * The function returns 1 if the object was actually found in the auto memory * pool, otherwise 0 is returned. */
| 1086 | * The function returns 1 if the object was actually found in the auto memory |
| 1087 | * pool, otherwise 0 is returned. */ |
| 1088 | int autoMemoryFreed(RedisModuleCtx *ctx, int type, void *ptr) { |
| 1089 | if (!(ctx->flags & REDISMODULE_CTX_AUTO_MEMORY)) return 0; |
| 1090 | |
| 1091 | int count = (ctx->amqueue_used+1)/2; |
| 1092 | for (int j = 0; j < count; j++) { |
| 1093 | for (int side = 0; side < 2; side++) { |
| 1094 | /* For side = 0 check right side of the array, for |
| 1095 | * side = 1 check the left side instead (zig-zag scanning). */ |
| 1096 | int i = (side == 0) ? (ctx->amqueue_used - 1 - j) : j; |
| 1097 | if (ctx->amqueue[i].type == type && |
| 1098 | ctx->amqueue[i].ptr == ptr) |
| 1099 | { |
| 1100 | ctx->amqueue[i].type = REDISMODULE_AM_FREED; |
| 1101 | |
| 1102 | /* Switch the freed element and the last element, to avoid growing |
| 1103 | * the queue unnecessarily if we allocate/free in a loop */ |
| 1104 | if (i != ctx->amqueue_used-1) { |
| 1105 | ctx->amqueue[i] = ctx->amqueue[ctx->amqueue_used-1]; |
| 1106 | } |
| 1107 | |
| 1108 | /* Reduce the size of the queue because we either moved the top |
| 1109 | * element elsewhere or freed it */ |
| 1110 | ctx->amqueue_used--; |
| 1111 | return 1; |
| 1112 | } |
| 1113 | } |
| 1114 | } |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | /* Release all the objects in queue. */ |
| 1119 | void autoMemoryCollect(RedisModuleCtx *ctx) { |
no outgoing calls
no test coverage detected