Skip to content

Commit 5d9bd14

Browse files
committed
MySQLnd: Remove some unnecessary allocator failure checks
emalloc/pemalloc are infallible.
1 parent 86e317a commit 5d9bd14

File tree

5 files changed

+7
-70
lines changed

5 files changed

+7
-70
lines changed

ext/mysqlnd/mysqlnd_auth.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ mysqlnd_run_authentication(
103103
}
104104
conn->authentication_plugin_data.l = plugin_data_len;
105105
conn->authentication_plugin_data.s = mnd_pemalloc(conn->authentication_plugin_data.l, conn->persistent);
106-
if (!conn->authentication_plugin_data.s) {
107-
SET_OOM_ERROR(conn->error_info);
108-
goto end;
109-
}
110106
memcpy(conn->authentication_plugin_data.s, plugin_data, plugin_data_len);
111107

112108
DBG_INF_FMT("salt(%d)=[%.*s]", plugin_data_len, plugin_data_len, plugin_data);

ext/mysqlnd/mysqlnd_commands.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ MYSQLND_METHOD(mysqlnd_command, init_db)(MYSQLND_CONN_DATA * const conn, const M
112112
}
113113
conn->connect_or_select_db.s = mnd_pestrndup(db.s, db.l, conn->persistent);
114114
conn->connect_or_select_db.l = db.l;
115-
if (!conn->connect_or_select_db.s) {
116-
/* OOM */
117-
SET_OOM_ERROR(conn->error_info);
118-
ret = FAIL;
119-
}
120115
}
121116

122117
DBG_RETURN(ret);

ext/mysqlnd/mysqlnd_connection.c

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -709,17 +709,8 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,
709709
conn->connect_or_select_db.l = database.l;
710710
conn->connect_or_select_db.s = mnd_pestrndup(database.s, conn->connect_or_select_db.l, conn->persistent);
711711

712-
if (!conn->username.s || !conn->password.s|| !conn->connect_or_select_db.s) {
713-
SET_OOM_ERROR(conn->error_info);
714-
goto err; /* OOM */
715-
}
716-
717712
if (!unix_socket && !named_pipe) {
718713
conn->hostname.s = mnd_pestrndup(hostname.s, hostname.l, conn->persistent);
719-
if (!conn->hostname.s) {
720-
SET_OOM_ERROR(conn->error_info);
721-
goto err; /* OOM */
722-
}
723714
conn->hostname.l = hostname.l;
724715
{
725716
char *p;
@@ -730,10 +721,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,
730721
}
731722
conn->host_info = mnd_pestrdup(p, conn->persistent);
732723
mnd_sprintf_free(p);
733-
if (!conn->host_info) {
734-
SET_OOM_ERROR(conn->error_info);
735-
goto err; /* OOM */
736-
}
737724
}
738725
} else {
739726
conn->unix_socket.s = mnd_pestrdup(socket_or_pipe.s, conn->persistent);
@@ -746,12 +733,8 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,
746733
SET_OOM_ERROR(conn->error_info);
747734
goto err; /* OOM */
748735
}
749-
conn->host_info = mnd_pestrdup(p, conn->persistent);
736+
conn->host_info = mnd_pestrdup(p, conn->persistent);
750737
mnd_sprintf_free(p);
751-
if (!conn->host_info) {
752-
SET_OOM_ERROR(conn->error_info);
753-
goto err; /* OOM */
754-
}
755738
} else {
756739
php_error_docref(NULL, E_WARNING, "Impossible. Should be either socket or a pipe. Report a bug!");
757740
}
@@ -1672,14 +1655,8 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(MYSQLND_CONN_DATA * const c
16721655
/* when num_commands is 0, then realloc will be effectively a malloc call, internally */
16731656
/* Don't assign to conn->options->init_commands because in case of OOM we will lose the pointer and leak */
16741657
new_init_commands = mnd_perealloc(conn->options->init_commands, sizeof(char *) * (conn->options->num_commands + 1), conn->persistent);
1675-
if (!new_init_commands) {
1676-
goto oom;
1677-
}
16781658
conn->options->init_commands = new_init_commands;
16791659
new_command = mnd_pestrdup(value, conn->persistent);
1680-
if (!new_command) {
1681-
goto oom;
1682-
}
16831660
conn->options->init_commands[conn->options->num_commands] = new_command;
16841661
++conn->options->num_commands;
16851662
break;
@@ -1702,9 +1679,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(MYSQLND_CONN_DATA * const c
17021679
}
17031680

17041681
new_charset_name = mnd_pestrdup(value, conn->persistent);
1705-
if (!new_charset_name) {
1706-
goto oom;
1707-
}
17081682
if (conn->options->charset_name) {
17091683
mnd_pefree(conn->options->charset_name, conn->persistent);
17101684
}
@@ -1740,9 +1714,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(MYSQLND_CONN_DATA * const c
17401714
case MYSQLND_OPT_AUTH_PROTOCOL:
17411715
{
17421716
char * new_auth_protocol = value? mnd_pestrdup(value, conn->persistent) : NULL;
1743-
if (value && !new_auth_protocol) {
1744-
goto oom;
1745-
}
17461717
if (conn->options->auth_protocol) {
17471718
mnd_pefree(conn->options->auth_protocol, conn->persistent);
17481719
}
@@ -1781,9 +1752,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(MYSQLND_CONN_DATA * const c
17811752
}
17821753
conn->m->local_tx_end(conn, this_func, ret);
17831754
DBG_RETURN(ret);
1784-
oom:
1785-
SET_OOM_ERROR(conn->error_info);
1786-
conn->m->local_tx_end(conn, this_func, FAIL);
17871755
end:
17881756
DBG_RETURN(FAIL);
17891757
}
@@ -1811,9 +1779,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option_2d)(MYSQLND_CONN_DATA * cons
18111779
if (!conn->options->connect_attr) {
18121780
DBG_INF("Initializing connect_attr hash");
18131781
conn->options->connect_attr = mnd_pemalloc(sizeof(HashTable), conn->persistent);
1814-
if (!conn->options->connect_attr) {
1815-
goto oom;
1816-
}
18171782
zend_hash_init(conn->options->connect_attr, 0, NULL, conn->persistent ? ZVAL_INTERNAL_PTR_DTOR : ZVAL_PTR_DTOR, conn->persistent);
18181783
}
18191784
DBG_INF_FMT("Adding [%s][%s]", key, value);
@@ -1839,9 +1804,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option_2d)(MYSQLND_CONN_DATA * cons
18391804
}
18401805
conn->m->local_tx_end(conn, this_func, ret);
18411806
DBG_RETURN(ret);
1842-
oom:
1843-
SET_OOM_ERROR(conn->error_info);
1844-
conn->m->local_tx_end(conn, this_func, FAIL);
18451807
end:
18461808
DBG_RETURN(FAIL);
18471809
}

ext/mysqlnd/mysqlnd_driver.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,10 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement)(MYSQLND_CONN_DATA
192192

193193
DBG_ENTER("mysqlnd_object_factory::get_prepared_statement");
194194
do {
195-
if (!ret) {
196-
break;
197-
}
198195
ret->m = mysqlnd_stmt_get_methods();
199196

200197
stmt = ret->data = mnd_ecalloc(1, sizeof(MYSQLND_STMT_DATA));
201198
DBG_INF_FMT("stmt=%p", stmt);
202-
if (!stmt) {
203-
break;
204-
}
205199

206200
if (FAIL == mysqlnd_error_info_init(&stmt->error_info_impl, 0)) {
207201
break;

ext/mysqlnd/mysqlnd_wireprotocol.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,14 +1074,9 @@ php_mysqlnd_rset_header_read(MYSQLND_CONN_DATA * conn, void * _packet)
10741074
*/
10751075
len = packet->header.size - 1;
10761076
packet->info_or_local_file.s = mnd_emalloc(len + 1);
1077-
if (packet->info_or_local_file.s) {
1078-
memcpy(packet->info_or_local_file.s, p, len);
1079-
packet->info_or_local_file.s[len] = '\0';
1080-
packet->info_or_local_file.l = len;
1081-
} else {
1082-
SET_OOM_ERROR(error_info);
1083-
ret = FAIL;
1084-
}
1077+
memcpy(packet->info_or_local_file.s, p, len);
1078+
packet->info_or_local_file.s[len] = '\0';
1079+
packet->info_or_local_file.l = len;
10851080
break;
10861081
case 0x00:
10871082
DBG_INF("UPSERT");
@@ -1101,14 +1096,9 @@ php_mysqlnd_rset_header_read(MYSQLND_CONN_DATA * conn, void * _packet)
11011096
/* Check for additional textual data */
11021097
if (packet->header.size > (size_t) (p - buf) && (len = php_mysqlnd_net_field_length(&p))) {
11031098
packet->info_or_local_file.s = mnd_emalloc(len + 1);
1104-
if (packet->info_or_local_file.s) {
1105-
memcpy(packet->info_or_local_file.s, p, len);
1106-
packet->info_or_local_file.s[len] = '\0';
1107-
packet->info_or_local_file.l = len;
1108-
} else {
1109-
SET_OOM_ERROR(error_info);
1110-
ret = FAIL;
1111-
}
1099+
memcpy(packet->info_or_local_file.s, p, len);
1100+
packet->info_or_local_file.s[len] = '\0';
1101+
packet->info_or_local_file.l = len;
11121102
}
11131103
DBG_INF_FMT("affected_rows=%llu last_insert_id=%llu server_status=%u warning_count=%u",
11141104
packet->affected_rows, packet->last_insert_id,

0 commit comments

Comments
 (0)