Skip to content

Commit 135260e

Browse files
committed
Merge pull request #25 from rurban/master
RT #97570: fix wrong salloc free in mysql_st_internal_execute
2 parents 8c207be + c570f90 commit 135260e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

dbdimp.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,8 +1952,13 @@ MYSQL *mysql_dr_connect(
19521952
/*
19531953
sock was allocated with mysql_init()
19541954
fixes: https://rt.cpan.org/Ticket/Display.html?id=86153
1955-
*/
1955+
19561956
Safefree(sock);
1957+
1958+
rurban: No, we still need this handle later in mysql_dr_error().
1959+
RT #97625. It will be freed as imp_dbh->pmysql in dbd_db_destroy(),
1960+
which is called by the DESTROY handler.
1961+
*/
19571962
}
19581963
return result;
19591964
}
@@ -1990,6 +1995,7 @@ static int my_login(pTHX_ SV* dbh, imp_dbh_t *imp_dbh)
19901995
char* user;
19911996
char* password;
19921997
char* mysql_socket;
1998+
int result;
19931999
D_imp_xxh(dbh);
19942000

19952001
/* TODO- resolve this so that it is set only if DBI is 1.607 */
@@ -2040,8 +2046,11 @@ static int my_login(pTHX_ SV* dbh, imp_dbh_t *imp_dbh)
20402046
if (!imp_dbh->pmysql) {
20412047
Newz(908, imp_dbh->pmysql, 1, MYSQL);
20422048
}
2043-
return mysql_dr_connect(dbh, imp_dbh->pmysql, mysql_socket, host, port, user,
2049+
result = mysql_dr_connect(dbh, imp_dbh->pmysql, mysql_socket, host, port, user,
20442050
password, dbname, imp_dbh) ? TRUE : FALSE;
2051+
if (!result)
2052+
Safefree(imp_dbh->pmysql);
2053+
return result;
20452054
}
20462055

20472056

@@ -3314,7 +3323,8 @@ my_ulonglong mysql_st_internal_execute(
33143323
}
33153324
#endif
33163325

3317-
Safefree(salloc);
3326+
if (salloc)
3327+
Safefree(salloc);
33183328

33193329
if(rows == -2) {
33203330
do_error(h, mysql_errno(svsock), mysql_error(svsock),

t/rt86153-reconnect-fail-memory.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ for (my $i = 0; $i < $COUNT_CONNECT; $i++) {
6363
$ok++;
6464
}
6565
else {
66+
diag "$prev_size => $size" if $ENV{TEST_VERBOSE};
6667
$not_ok++;
6768
}
6869
}

0 commit comments

Comments
 (0)