{"record":{"id":"6b1b2ece145f7d03","repo":"mudler/LocalAI","slug":"failed-to-allocate-memory-for-resized-reference-im","errorCode":null,"errorMessage":"Failed to allocate memory for resized reference image\\n","messagePattern":"Failed to allocate memory for resized reference image\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/go/stablediffusion-ggml/cpp/gosd.cpp","lineNumber":960,"sourceCode":"            int ref_height = 0;\n            uint8_t* ref_image_buffer = stbi_load(ref_images[i], &ref_width, &ref_height, &c, 3);\n            if (ref_image_buffer == NULL) {\n                fprintf(stderr, \"Failed to load reference image from '%s'\\n\", ref_images[i]);\n                continue;\n            }\n            if (c < 3) {\n                fprintf(stderr, \"Reference image must have at least 3 channels, got %d\\n\", c);\n                free(ref_image_buffer);\n                continue;\n            }\n\n            // Resize reference image if dimensions don't match\n            if (ref_width != width || ref_height != height) {\n                fprintf(stderr, \"Resizing reference image from %dx%d to %dx%d\\n\", ref_width, ref_height, width, height);\n\n                uint8_t* resized_ref_buffer = (uint8_t*)malloc(height * width * 3);\n                if (resized_ref_buffer == NULL) {\n                    fprintf(stderr, \"Failed to allocate memory for resized reference image\\n\");\n                    free(ref_image_buffer);\n                    continue;\n                }\n\n                stbir_resize(ref_image_buffer, ref_width, ref_height, 0,\n                             resized_ref_buffer, width, height, 0, STBIR_TYPE_UINT8,\n                             3, 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(ref_image_buffer);\n                ref_image_buffer = resized_ref_buffer;\n            }\n\n            ref_image_buffers.push_back(ref_image_buffer);\n            ref_images_vec.push_back({(uint32_t)width, (uint32_t)height, 3, ref_image_buffer});\n        }","sourceCodeStart":942,"sourceCodeEnd":978,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/stablediffusion-ggml/cpp/gosd.cpp#L942-L978","documentation":"Allocation for the resized reference image buffer failed. Guard: validate image dimensions are within sane bounds before allocating; on failure abort with an out-of-memory error instead of dereferencing null.","triggerScenarios":"Thrown at backend/go/stablediffusion-ggml/cpp/gosd.cpp:960 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Free memory or reduce reference image dimensions so the resize allocation succeeds.","Check overall memory usage of the backend process."],"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"}