Subdiv: Fix memory leak
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 10 Jan 2019 16:08:31 +0000 (17:08 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 10 Jan 2019 16:09:48 +0000 (17:09 +0100)
Was visible when mesh had n-gons.

source/blender/blenkernel/intern/subdiv_foreach.c

index 2cfcc137ba509f11e0d1b01935c7c2f2122f0b91..5c843561a4d5490fe03c2204800ba945e21f6728 100644 (file)
@@ -148,11 +148,15 @@ static void *subdiv_foreach_tls_alloc(SubdivForeachTaskContext *ctx)
        return tls;
 }
 
-static void subdiv_foreach_tls_free(void *tls)
+static void subdiv_foreach_tls_free(SubdivForeachTaskContext *ctx, void *tls)
 {
-       if (tls != NULL) {
-               MEM_freeN(tls);
+       if (tls == NULL) {
+               return;
+       }
+       if (ctx->foreach_context != NULL) {
+               ctx->foreach_context->user_data_tls_free(tls);
        }
+       MEM_freeN(tls);
 }
 
 /* =============================================================================
@@ -1972,7 +1976,7 @@ static void subdiv_foreach_single_thread_tasks(SubdivForeachTaskContext *ctx)
        subdiv_foreach_every_edge_vertices(ctx, tls);
        /* Run callbacks which are supposed to be run once per shared geometry. */
        subdiv_foreach_single_geometry_vertices(ctx, tls);
-       subdiv_foreach_tls_free(tls);
+       subdiv_foreach_tls_free(ctx, tls);
 }
 
 static void subdiv_foreach_task(