From c1b922f094299e515341421640cc3d73a76d7c41 Mon Sep 17 00:00:00 2001 From: monster29000 <1067752807@qq.com> Date: Tue, 13 Aug 2024 08:53:12 +0800 Subject: [PATCH] Smart Pointer Recommendations --- .vscode/settings.json | 45 ++++++++++++++++++++++++++++++++ ijkmedia/ijksdl/gles2/internal.h | 2 ++ ijkmedia/ijksdl/gles2/renderer.c | 7 +++-- ijkmedia/ijksdl/gles2/shader.c | 7 +++-- 4 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..1ba86a6fd8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,45 @@ +{ + "files.associations": { + "*.cu": "cuda-cpp", + "array": "c", + "atomic": "c", + "*.tcc": "c", + "cctype": "c", + "clocale": "c", + "cmath": "c", + "cstdarg": "c", + "cstddef": "c", + "cstdint": "c", + "cstdio": "c", + "cstdlib": "c", + "cwchar": "c", + "cwctype": "c", + "deque": "c", + "unordered_map": "c", + "vector": "c", + "exception": "c", + "algorithm": "c", + "map": "c", + "memory": "c", + "memory_resource": "c", + "optional": "c", + "string": "c", + "string_view": "c", + "system_error": "c", + "tuple": "c", + "type_traits": "c", + "utility": "c", + "fstream": "c", + "initializer_list": "c", + "iosfwd": "c", + "istream": "c", + "limits": "c", + "new": "c", + "ostream": "c", + "sstream": "c", + "stdexcept": "c", + "streambuf": "c", + "cinttypes": "c", + "typeinfo": "c" + } +} \ No newline at end of file diff --git a/ijkmedia/ijksdl/gles2/internal.h b/ijkmedia/ijksdl/gles2/internal.h index edafc1daaf..d4378efe74 100644 --- a/ijkmedia/ijksdl/gles2/internal.h +++ b/ijkmedia/ijksdl/gles2/internal.h @@ -24,6 +24,8 @@ #include #include +#include +#include #include "ijksdl/ijksdl_fourcc.h" #include "ijksdl/ijksdl_log.h" #include "ijksdl/ijksdl_gles2.h" diff --git a/ijkmedia/ijksdl/gles2/renderer.c b/ijkmedia/ijksdl/gles2/renderer.c index 76c61273a2..9888d52fe2 100644 --- a/ijkmedia/ijksdl/gles2/renderer.c +++ b/ijkmedia/ijksdl/gles2/renderer.c @@ -34,11 +34,10 @@ static void IJK_GLES2_printProgramInfo(GLuint program) } char buf_stack[32]; - char *buf_heap = NULL; + std::unique_ptr buf_heap = std::make_unique(info_len + 1); char *buf = buf_stack; GLsizei buf_len = sizeof(buf_stack) - 1; if (info_len > sizeof(buf_stack)) { - buf_heap = (char*) malloc(info_len + 1); if (buf_heap) { buf = buf_heap; buf_len = info_len; @@ -48,8 +47,8 @@ static void IJK_GLES2_printProgramInfo(GLuint program) glGetProgramInfoLog(program, buf_len, NULL, buf); ALOGE("[GLES2][Program] error %s\n", buf); - if (buf_heap) - free(buf_heap); + // if (buf_heap) + // free(buf_heap); } void IJK_GLES2_Renderer_reset(IJK_GLES2_Renderer *renderer) diff --git a/ijkmedia/ijksdl/gles2/shader.c b/ijkmedia/ijksdl/gles2/shader.c index f40679821c..ba698723df 100644 --- a/ijkmedia/ijksdl/gles2/shader.c +++ b/ijkmedia/ijksdl/gles2/shader.c @@ -34,11 +34,10 @@ static void IJK_GLES2_printShaderInfo(GLuint shader) } char buf_stack[32]; - char *buf_heap = NULL; + std::unique_ptr buf_heap = std::make_unique(info_len + 1); char *buf = buf_stack; GLsizei buf_len = sizeof(buf_stack) - 1; if (info_len > sizeof(buf_stack)) { - buf_heap = (char*) malloc(info_len + 1); if (buf_heap) { buf = buf_heap; buf_len = info_len; @@ -48,8 +47,8 @@ static void IJK_GLES2_printShaderInfo(GLuint shader) glGetShaderInfoLog(shader, buf_len, NULL, buf); ALOGE("[GLES2][Shader] error %s\n", buf); - if (buf_heap) - free(buf_heap); + // if (buf_heap) + // free(buf_heap); } GLuint IJK_GLES2_loadShader(GLenum shader_type, const char *shader_source)