Skip to content

Commit e16aa16

Browse files
authored
Fix memory leaks in plugins (#13028)
* Fix leak in client_context_dump — free results array after iterating context names in CB_context_dump. * Fix leak in s3_auth ConfigCache — add destructor to delete all cached S3Config pointers on shutdown. * Fix leak in stale_response — free log_info.filename in ConfigInfo destructor when strdup()d.
1 parent 72ad8fb commit e16aa16

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

example/plugins/c-api/client_context_dump/client_context_dump.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ CB_context_dump(TSCont, TSEvent, void *edata)
163163
for (int i = 0; i < count; i += 2) {
164164
dump_context(results[i], results[i + 1]);
165165
}
166+
free(results);
166167
}
167168
}
168169
TSTextLogObjectFlush(context_dump_log);

plugins/experimental/stale_response/stale_response.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#pragma once
2525

26+
#include <cstdlib>
27+
2628
#include "ts/apidefs.h"
2729
#include "ts_wrap.h"
2830
#include "ts/ts.h"
@@ -63,6 +65,9 @@ struct ConfigInfo {
6365
if (this->body_data_mutex) {
6466
TSMutexDestroy(this->body_data_mutex);
6567
}
68+
if (this->log_info.filename != PLUGIN_TAG) {
69+
free(const_cast<char *>(this->log_info.filename));
70+
}
6671
}
6772
UintBodyMap *body_data = nullptr;
6873
TSMutex body_data_mutex;

plugins/origin_server_auth/origin_server_auth.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ class S3Config;
154154
class ConfigCache
155155
{
156156
public:
157+
~ConfigCache();
158+
157159
S3Config *get(const char *fname);
158160

159161
private:
@@ -601,6 +603,13 @@ class S3Config
601603
int _invalid_file_count = 0;
602604
};
603605

606+
ConfigCache::~ConfigCache()
607+
{
608+
for (auto &[key, data] : _cache) {
609+
delete data.config.load();
610+
}
611+
}
612+
604613
bool
605614
S3Config::parse_config(const std::string &config_fname)
606615
{

0 commit comments

Comments
 (0)