{"record":{"id":"ba9729cc339b02b8","repo":"mudler/LocalAI","slug":"failed-to-allocate-memory-for-resized-mask-n","errorCode":null,"errorMessage":"Failed to allocate memory for resized mask\\n","messagePattern":"Failed to allocate memory for resized mask\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/go/stablediffusion-ggml/cpp/gosd.cpp","lineNumber":901,"sourceCode":"        fprintf(stderr, \"Loading mask image: %s\\n\", mask_image);\n\n        int c = 0;\n        int mask_width = 0;\n        int mask_height = 0;\n        mask_image_buffer = stbi_load(mask_image, &mask_width, &mask_height, &c, 1);\n        if (mask_image_buffer == NULL) {\n            fprintf(stderr, \"Failed to load mask image from '%s'\\n\", mask_image);\n            if (input_image_buffer) free(input_image_buffer);\n            return 1;\n        }\n\n        // Resize mask if dimensions don't match\n        if (mask_width != width || mask_height != height) {\n            fprintf(stderr, \"Resizing mask image from %dx%d to %dx%d\\n\", mask_width, mask_height, width, height);\n\n            uint8_t* resized_mask_buffer = (uint8_t*)malloc(height * width);\n            if (resized_mask_buffer == NULL) {\n                fprintf(stderr, \"Failed to allocate memory for resized mask\\n\");\n                free(mask_image_buffer);\n                if (input_image_buffer) free(input_image_buffer);\n                return 1;\n            }\n\n            stbir_resize(mask_image_buffer, mask_width, mask_height, 0,\n                         resized_mask_buffer, width, height, 0, STBIR_TYPE_UINT8,\n                         1, STBIR_ALPHA_CHANNEL_NONE, 0,\n                         STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP,\n                         STBIR_FILTER_BOX, STBIR_FILTER_BOX,\n                         STBIR_COLORSPACE_SRGB, nullptr);\n\n            free(mask_image_buffer);\n            mask_image_buffer = resized_mask_buffer;\n        }\n\n        p->mask_image = {(uint32_t)width, (uint32_t)height, 1, mask_image_buffer};\n        fprintf(stderr, \"Using inpainting with mask\\n\");","sourceCodeStart":883,"sourceCodeEnd":919,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/stablediffusion-ggml/cpp/gosd.cpp#L883-L919","documentation":"Allocation for the resized mask buffer failed. Guard: validate mask dimensions are within sane bounds before allocating; on allocation failure abort the request with an out-of-memory error instead of dereferencing null.","triggerScenarios":"Thrown at backend/go/stablediffusion-ggml/cpp/gosd.cpp:901 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Free system memory or reduce mask image dimensions so the resize allocation fits.","Check for memory pressure from other processes on the host."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}