1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

fix: fixed a possible leak when one of the files (fp1 or fp2) fails to

open by adding a simple condition that checks whether one of them opens
while the other fails and closing it
and added the extra prentheses for the assignment inside the if statement
for easier debugging and to avoid static analysis flagging it as a wrong
statement inside the if clause
This commit is contained in:
Pavol Sloboda
2025-04-11 11:45:53 +02:00
committed by Georg Richter
parent c10a3479fb
commit 9e4042c149

View File

@@ -1521,6 +1521,7 @@ static int test_conc327(MYSQL *unused __attribute__((unused)))
const char *env= getenv("MYSQL_TMP_DIR");
char cnf_file1[FN_REFLEN + 1];
char cnf_file2[FN_REFLEN + 1];
my_bool failed_opening_files;
SKIP_SKYSQL;
@@ -1539,7 +1540,19 @@ static int test_conc327(MYSQL *unused __attribute__((unused)))
fp1= fopen(cnf_file1, "w");
fp2= fopen(cnf_file2, "w");
FAIL_IF(!fp1 || !fp2, "fopen failed");
if((failed_opening_files = !fp1 || !fp2))
{
if(fp1)
{
fclose(fp1);
}
if(fp2)
{
fclose(fp2);
}
}
FAIL_IF(failed_opening_files, "fopen failed");
fprintf(fp1, "!include %s\n", cnf_file2);
@@ -1564,7 +1577,18 @@ static int test_conc327(MYSQL *unused __attribute__((unused)))
snprintf(cnf_file1, FN_REFLEN, "%s%cmy.cnf", env, FN_LIBCHAR);
fp1= fopen(cnf_file1, "w");
fp2= fopen(cnf_file2, "w");
FAIL_IF(!fp1 || !fp2, "fopen failed");
if((failed_opening_files = !fp1 || !fp2))
{
if(fp1)
{
fclose(fp1);
}
if(fp2)
{
fclose(fp2);
}
}
FAIL_IF(failed_opening_files, "fopen failed");
fprintf(fp2, "!includedir %s\n", env);