glewInit() 根据 valgrind 导致内存泄漏

glewInit() Causes memory leak according to valgrind

我正在尝试调试和修复程序中的所有内存泄漏。我浏览了整个源代码,没有一个 newmalloc() 的调用是 free()delete 不支持的。我在 valgrind 中尝试了 运行 程序。 Valgrind 发现一致(贯穿程序的多次执行)844 字节的数据肯定丢失了。它还不断将我指向 Window class 的 glewInit() 函数。我做错了什么吗?

注意事项:

class Window {
public:

     // void create(unsigned int width, unsigned int height, const std::string& name, bool resizable, bool decorated){
    //
    // }

    static void create(unsigned int width, unsigned int height, const std::string& name, bool resizable, bool decorated){

         if(!glfwInit()){
              Utils::log("Failed to initialize GLFW");
            return;
         }


         //Setting Window settings
         glfwWindowHint(GLFW_RED_BITS, 8);
         glfwWindowHint(GLFW_GREEN_BITS, 8);
         glfwWindowHint(GLFW_BLUE_BITS, 8);
         glfwWindowHint(GLFW_ALPHA_BITS, 8);
         glfwWindowHint(GLFW_DEPTH_BITS, 24);
         glfwWindowHint(GLFW_STENCIL_BITS, 8);
         glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
         glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
         glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
         glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
         glfwWindowHint(GLFW_SAMPLES, 4);
         glfwWindowHint(GLFW_RESIZABLE, resizable ? GLFW_TRUE : GLFW_FALSE);
         glfwWindowHint(GLFW_DECORATED, decorated ? GLFW_TRUE : GLFW_FALSE);

         m_width = width;
         m_height = height;

    #ifdef __APPLE__
         glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    #endif

         //Creating the window
         window = glfwCreateWindow(width, height, name.c_str(), NULL, NULL);
         if(!window){
              Utils::log("Window: Failed to create window");
            return;
         }

         //Settings for window
         glfwSwapInterval(1);
         glfwSetFramebufferSizeCallback(window, windowResized);

         //Creating the context for opengl
         glfwMakeContextCurrent(window);

         //Initializing glew
         if(glewInit() != GLEW_OK){
              Utils::log("Window: Failed to initialize glew");
         }

         //Enabling transparency
         glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

         //Enabling depth
         glEnable(GL_DEPTH_TEST);
         glClearDepthf(1.0f);

         //Enabling back face culling
         glEnable(GL_CULL_FACE);
         glCullFace(GL_BACK);

         //Enabling MSAA
         glEnable(GL_MULTISAMPLE);

         InputManager::init(window);

    }
     static void clear();
     static void update();
     static void close();

     //Window functions
     static void setVerticalSyncEnabled(bool enabled);
     static void setMouseCursorGrabbed(bool grabbed);
     static int getWidth();
     static int getHeight();
     static bool isResized();

     static bool isCloseRequested();

     static GLFWwindow* window;


private:

     static void windowResized(GLFWwindow* window, int width, int height);

     static int m_width;
     static int m_height;

     static bool m_isResized;
     static bool m_closeRequested;


};
#endif

我开始使用 GLAD,它不再导致内存泄漏。