crypto/rand/randfile.c:95: error: RESOURCE_LEAK
  resource of type `_IO_FILE` acquired by call to `openssl_fopen()` at line 87, column 15 is not released after line 95, column 9.
Showing all 12 steps of the trace


crypto/rand/randfile.c:75:1: start of procedure RAND_load_file()
73.    * -1 read the complete file; otherwise read the specified amount.
74.    */
75. > int RAND_load_file(const char *file, long bytes)
76.   {
77.       unsigned char buf[RAND_FILE_SIZE];

crypto/rand/randfile.c:81:5: 
79.       struct stat sb;
80.   #endif
81. >     int i, n, ret = 0;
82.       FILE *in;
83.   

crypto/rand/randfile.c:84:9: Taking false branch
82.       FILE *in;
83.   
84.       if (bytes == 0)
              ^
85.           return 0;
86.   

crypto/rand/randfile.c:87:9: 
85.           return 0;
86.   
87. >     if ((in = openssl_fopen(file, "rb")) == NULL) {
88.           RANDerr(RAND_F_RAND_LOAD_FILE, RAND_R_CANNOT_OPEN_FILE);
89.           ERR_add_error_data(2, "Filename=", file);

crypto/o_fopen.c:22:1: start of procedure openssl_fopen()
  20.   # endif
  21.   
  22. > FILE *openssl_fopen(const char *filename, const char *mode)
  23.   {
  24.       FILE *file = NULL;

crypto/o_fopen.c:24:5: 
  22.   FILE *openssl_fopen(const char *filename, const char *mode)
  23.   {
  24. >     FILE *file = NULL;
  25.   # if defined(_WIN32) && defined(CP_UTF8)
  26.       int sz, len_0 = (int)strlen(filename) + 1;

crypto/o_fopen.c:97:5: 
  95.       }
  96.   # else
  97. >     file = fopen(filename, mode);
  98.   # endif
  99.       return file;

crypto/o_fopen.c:99:5: 
  97.       file = fopen(filename, mode);
  98.   # endif
  99. >     return file;
  100.   }
  101.   

crypto/o_fopen.c:100:1: return from a call to openssl_fopen
  98.   # endif
  99.       return file;
  100. > }
  101.   
  102.   #else

crypto/rand/randfile.c:87:9: Taking false branch
85.           return 0;
86.   
87.       if ((in = openssl_fopen(file, "rb")) == NULL) {
              ^
88.           RANDerr(RAND_F_RAND_LOAD_FILE, RAND_R_CANNOT_OPEN_FILE);
89.           ERR_add_error_data(2, "Filename=", file);

crypto/rand/randfile.c:94:9: Taking true branch
92.   
93.   #ifndef OPENSSL_NO_POSIX_IO
94.       if (fstat(fileno(in), &sb) < 0) {
              ^
95.           RANDerr(RAND_F_RAND_LOAD_FILE, RAND_R_INTERNAL_ERROR);
96.           ERR_add_error_data(2, "Filename=", file);

crypto/rand/randfile.c:95:9: Skipping ERR_put_error(): empty list of specs
93.   #ifndef OPENSSL_NO_POSIX_IO
94.       if (fstat(fileno(in), &sb) < 0) {
95.           RANDerr(RAND_F_RAND_LOAD_FILE, RAND_R_INTERNAL_ERROR);
              ^
96.           ERR_add_error_data(2, "Filename=", file);
97.           return -1;

int RAND_load_file(const char *file, long bytes)
{
    unsigned char buf[RAND_FILE_SIZE];
#ifndef OPENSSL_NO_POSIX_IO
    struct stat sb;
#endif
    int i, n, ret = 0;
    FILE *in;
    if (bytes == 0)
        return 0;
    if ((in = openssl_fopen(file, "rb")) == NULL) {
        RANDerr(RAND_F_RAND_LOAD_FILE, RAND_R_CANNOT_OPEN_FILE);
        ERR_add_error_data(2, "Filename=", file);
        return -1;
    }
#ifndef OPENSSL_NO_POSIX_IO
    if (fstat(fileno(in), &sb) < 0) {
        RANDerr(RAND_F_RAND_LOAD_FILE, RAND_R_INTERNAL_ERROR);
        ERR_add_error_data(2, "Filename=", file);
        return -1;
    }
    if (!S_ISREG(sb.st_mode) && bytes < 0)
        bytes = 256;
#endif
    setbuf(in, NULL);
    for ( ; ; ) {
        if (bytes > 0)
            n = (bytes < RAND_FILE_SIZE) ? (int)bytes : RAND_FILE_SIZE;
        else
            n = RAND_FILE_SIZE;
        i = fread(buf, 1, n, in);
#ifdef EINTR
        if (ferror(in) && errno == EINTR){
            clearerr(in);
            if (i == 0)
                continue;
        }
#endif
        if (i == 0)
            break;
        RAND_add(buf, i, (double)i);
        ret += i;
        if (bytes > 0 && (bytes -= i) <= 0)
            break;
    }
    OPENSSL_cleanse(buf, sizeof(buf));
    fclose(in);
    return ret;
}
['int RAND_load_file(const char *file, long bytes)\n{\n    unsigned char buf[RAND_FILE_SIZE];\n#ifndef OPENSSL_NO_POSIX_IO\n    struct stat sb;\n#endif\n    int i, n, ret = 0;\n    FILE *in;\n    if (bytes == 0)\n        return 0;\n    if ((in = openssl_fopen(file, "rb")) == NULL) {\n        RANDerr(RAND_F_RAND_LOAD_FILE, RAND_R_CANNOT_OPEN_FILE);\n        ERR_add_error_data(2, "Filename=", file);\n        return -1;\n    }\n#ifndef OPENSSL_NO_POSIX_IO\n    if (fstat(fileno(in), &sb) < 0) {\n        RANDerr(RAND_F_RAND_LOAD_FILE, RAND_R_INTERNAL_ERROR);\n        ERR_add_error_data(2, "Filename=", file);\n        return -1;\n    }\n    if (!S_ISREG(sb.st_mode) && bytes < 0)\n        bytes = 256;\n#endif\n    setbuf(in, NULL);\n    for ( ; ; ) {\n        if (bytes > 0)\n            n = (bytes < RAND_FILE_SIZE) ? (int)bytes : RAND_FILE_SIZE;\n        else\n            n = RAND_FILE_SIZE;\n        i = fread(buf, 1, n, in);\n#ifdef EINTR\n        if (ferror(in) && errno == EINTR){\n            clearerr(in);\n            if (i == 0)\n                continue;\n        }\n#endif\n        if (i == 0)\n            break;\n        RAND_add(buf, i, (double)i);\n        ret += i;\n        if (bytes > 0 && (bytes -= i) <= 0)\n            break;\n    }\n    OPENSSL_cleanse(buf, sizeof(buf));\n    fclose(in);\n    return ret;\n}', "FILE *openssl_fopen(const char *filename, const char *mode)\n{\n    FILE *file = NULL;\n# if defined(_WIN32) && defined(CP_UTF8)\n    int sz, len_0 = (int)strlen(filename) + 1;\n    DWORD flags;\n    if ((sz = MultiByteToWideChar(CP_UTF8, (flags = MB_ERR_INVALID_CHARS),\n                                  filename, len_0, NULL, 0)) > 0 ||\n        (GetLastError() == ERROR_INVALID_FLAGS &&\n         (sz = MultiByteToWideChar(CP_UTF8, (flags = 0),\n                                   filename, len_0, NULL, 0)) > 0)\n        ) {\n        WCHAR wmode[8];\n        WCHAR *wfilename = _alloca(sz * sizeof(WCHAR));\n        if (MultiByteToWideChar(CP_UTF8, flags,\n                                filename, len_0, wfilename, sz) &&\n            MultiByteToWideChar(CP_UTF8, 0, mode, strlen(mode) + 1,\n                                wmode, OSSL_NELEM(wmode)) &&\n            (file = _wfopen(wfilename, wmode)) == NULL &&\n            (errno == ENOENT || errno == EBADF)\n            ) {\n            file = fopen(filename, mode);\n        }\n    } else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) {\n        file = fopen(filename, mode);\n    }\n# elif defined(__DJGPP__)\n    {\n        char *newname = NULL;\n        if (pathconf(filename, _PC_NAME_MAX) <= 12) {\n            char *iterator;\n            char lastchar;\n            newname = OPENSSL_malloc(strlen(filename) + 1);\n            if (newname == NULL)\n                return NULL;\n            for (iterator = newname, lastchar = '\\0';\n                *filename; filename++, iterator++) {\n                if (lastchar == '/' && filename[0] == '.'\n                    && filename[1] != '.' && filename[1] != '/') {\n                    *iterator = '_';\n                } else {\n                    *iterator = *filename;\n                }\n                lastchar = *filename;\n            }\n            *iterator = '\\0';\n            filename = newname;\n        }\n        file = fopen(filename, mode);\n        OPENSSL_free(newname);\n    }\n# else\n    file = fopen(filename, mode);\n# endif\n    return file;\n}"]