Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 32f6f78

Browse files
authored
Merge pull request #3222 from eduar-hte/remove-copies
Remove several string copies and unnecessary heap allocations
2 parents 305f33f + 77adb57 commit 32f6f78

File tree

8 files changed

+249
-365
lines changed

8 files changed

+249
-365
lines changed

‎src/Makefile.am‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ UTILS = \
253253
utils/random.cc \
254254
utils/regex.cc \
255255
utils/sha1.cc \
256-
utils/string.cc \
257256
utils/system.cc \
258257
utils/shared_files.cc
259258

‎src/request_body_processor/multipart.cc‎

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,20 @@ void MultipartPartTmpFile::Open() {
7070

7171
localtime_r(&tt, &timeinfo);
7272

73-
char tstr[300] {};
74-
strftime(tstr, 299, "/%Y%m%d-%H%M%S", &timeinfo);
73+
char tstr[17];
74+
strftime(tstr, std::size(tstr), "/%Y%m%d-%H%M%S", &timeinfo);
7575

7676
std::string path = m_transaction->m_rules->m_uploadDirectory.m_value;
7777
path = path + tstr + "-" + *m_transaction->m_id.get();
7878
path += "-file-XXXXXX";
7979

80-
char* tmp = strdup(path.c_str());
8180
#ifndef WIN32
82-
m_tmp_file_fd = mkstemp(tmp);
81+
m_tmp_file_fd = mkstemp(path.data());
8382
#else
84-
_mktemp_s(tmp, path.length()+1);
85-
m_tmp_file_fd = _open(tmp, _O_CREAT | _O_EXCL | _O_RDWR);
83+
_mktemp_s(path.data(), path.length()+1);
84+
m_tmp_file_fd = _open(path.c_str(), _O_CREAT | _O_EXCL | _O_RDWR);
8685
#endif
87-
m_tmp_file_name.assign(tmp);
88-
free(tmp);
86+
m_tmp_file_name = path;
8987
ms_dbg_a(m_transaction, 4, "MultipartPartTmpFile: Create filename= " + m_tmp_file_name);
9088

9189
int mode = m_transaction->m_rules->m_uploadFileMode.m_value;
@@ -857,7 +855,7 @@ int Multipart::process_part_header(std::string *error, int offset) {
857855
}
858856

859857
new_value = std::string(data);
860-
utils::string::chomp(&new_value);
858+
utils::string::chomp(new_value);
861859

862860
/* update the header value in the table */
863861
header_value = m_mpp->m_headers.at(
@@ -926,7 +924,7 @@ int Multipart::process_part_header(std::string *error, int offset) {
926924
i++;
927925
}
928926
header_value = std::string(data);
929-
utils::string::chomp(&header_value);
927+
utils::string::chomp(header_value);
930928

931929
/* error if the name already exists */
932930
if (m_mpp->m_headers.count(header_name) > 0) {
@@ -1271,22 +1269,10 @@ int Multipart::multipart_complete(std::string *error) {
12711269

12721270

12731271
int Multipart::count_boundary_params(const std::string& str_header_value) {
1274-
std::string lower = utils::string::tolower(str_header_value);
1275-
const char *header_value = lower.c_str();
1276-
char *duplicate = NULL;
1277-
char *s = NULL;
12781272
int count = 0;
12791273

1280-
if (header_value == NULL) {
1281-
return -1;
1282-
}
1283-
1284-
duplicate = strdup(header_value);
1285-
if (duplicate == NULL) {
1286-
return -1;
1287-
}
1288-
1289-
s = duplicate;
1274+
const auto lower = utils::string::tolower(str_header_value);
1275+
const char *s = lower.c_str();
12901276
while ((s = strstr(s, "boundary")) != NULL) {
12911277
s += 8;
12921278

@@ -1295,7 +1281,6 @@ int Multipart::count_boundary_params(const std::string& str_header_value) {
12951281
}
12961282
}
12971283

1298-
free(duplicate);
12991284
return count;
13001285
}
13011286

‎src/transaction.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ std::string Transaction::toOldAuditLogFormatIndex(const std::string &filename,
15201520
ss << utils::string::dash_if_empty(
15211521
m_variableRequestHeaders.resolveFirst("Host").get())
15221522
<< " ";
1523-
ss << utils::string::dash_if_empty(this->m_clientIpAddress->c_str()) << " ";
1523+
ss << utils::string::dash_if_empty(this->m_clientIpAddress.get()) << " ";
15241524
/** TODO: Check variable */
15251525
variables::RemoteUser *r = new variables::RemoteUser("REMOTE_USER");
15261526
std::vector<const VariableValue *> l;
@@ -1531,7 +1531,7 @@ std::string Transaction::toOldAuditLogFormatIndex(const std::string &filename,
15311531
delete r;
15321532

15331533
ss << utils::string::dash_if_empty(
1534-
m_variableRemoteUser.c_str());
1534+
&m_variableRemoteUser);
15351535
ss << " ";
15361536
/** TODO: Check variable */
15371537
//ss << utils::string::dash_if_empty(

‎src/utils/string.cc‎

Lines changed: 0 additions & 268 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /