diff options
author | Haru <haru@dotalux.com> | 2015-09-15 15:04:50 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2015-10-11 00:24:21 +0200 |
commit | 542a86978485e3671745aecfd94fa15fc3b1c73b (patch) | |
tree | 82b85912745ca249e86a7d22b030440916af768a | |
parent | 437dc70ac6a19fe9a32c095ada8205dce173beb3 (diff) | |
download | hercules-542a86978485e3671745aecfd94fa15fc3b1c73b.tar.gz hercules-542a86978485e3671745aecfd94fa15fc3b1c73b.tar.bz2 hercules-542a86978485e3671745aecfd94fa15fc3b1c73b.tar.xz hercules-542a86978485e3671745aecfd94fa15fc3b1c73b.zip |
Changed HPM->fnames to a vector type, renamed to HPM->filenames
- This is a generic vector. It doesn't make use of the VECTOR type
because it needs to outlive the memory manager.
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r-- | src/common/HPM.c | 58 | ||||
-rw-r--r-- | src/common/HPM.h | 7 |
2 files changed, 41 insertions, 24 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c index 0bbfbbb49..5f3aec8ab 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -705,23 +705,33 @@ char *hplugins_id2name(unsigned int pid) return "UnknownPlugin"; } -char* HPM_file2ptr(const char *file) { - unsigned int i; - for(i = 0; i < HPM->fnamec; i++) { - if( HPM->fnames[i].addr == file ) - return HPM->fnames[i].name; - } +/** + * Returns a retained permanent pointer to a source filename, for memory-manager reporting use. + * + * The returned pointer is safe to be used as filename in the memory manager + * functions, and it will be available during and after the memory manager + * shutdown (for memory leak reporting purposes). + * + * @param file The string/filename to retain + * @return A retained copy of the source string. + */ +const char *HPM_file2ptr(const char *file) +{ + int i; - i = HPM->fnamec; + ARR_FIND(0, HPM->filenames.count, i, HPM->filenames.data[i].addr == file); + if (i != HPM->filenames.count) { + return HPM->filenames.data[i].name; + } /* we handle this memory outside of the server's memory manager because we need it to exist after the memory manager goes down */ - HPM->fnames = realloc(HPM->fnames,(++HPM->fnamec)*sizeof(struct HPMFileNameCache)); + HPM->filenames.data = realloc(HPM->filenames.data, (++HPM->filenames.count)*sizeof(struct HPMFileNameCache)); - HPM->fnames[i].addr = file; - HPM->fnames[i].name = strdup(file); + HPM->filenames.data[i].addr = file; + HPM->filenames.data[i].name = strdup(file); - return HPM->fnames[i].name; + return HPM->filenames.data[i].name; } void* HPM_mmalloc(size_t size, const char *file, int line, const char *func) { return iMalloc->malloc(size,HPM_file2ptr(file),line,func); @@ -842,18 +852,25 @@ void hpm_init(void) { #endif return; } + +/** + * Releases the retained filenames cache. + */ void hpm_memdown(void) { - /* this memory is handled outside of the server's memory manager and thus cleared after memory manager goes down */ - - if (HPM->fnames) { - unsigned int i; - for (i = 0; i < HPM->fnamec; i++) { - free(HPM->fnames[i].name); + /* this memory is handled outside of the server's memory manager and + * thus cleared after memory manager goes down */ + if (HPM->filenames.count) { + int i; + for (i = 0; i < HPM->filenames.count; i++) { + free(HPM->filenames.data[i].name); } - free(HPM->fnames); + free(HPM->filenames.data); + HPM->filenames.data = NULL; + HPM->filenames.count = 0; } } + void hpm_final(void) { int i; @@ -896,13 +913,10 @@ void hpm_defaults(void) { unsigned int i; HPM = &HPM_s; - HPM->fnames = NULL; - HPM->fnamec = 0; + memset(&HPM->filenames, 0, sizeof(HPM->filenames)); HPM->force_return = false; HPM->hooking = false; /* */ - HPM->fnames = NULL; - HPM->fnamec = 0; for(i = 0; i < HPCT_MAX; i++) { HPM->confs[i] = NULL; HPM->confsc[i] = 0; diff --git a/src/common/HPM.h b/src/common/HPM.h index adbba5eda..e8cc02f6f 100644 --- a/src/common/HPM.h +++ b/src/common/HPM.h @@ -111,8 +111,11 @@ struct HPM_interface { /* packet hooking points */ VECTOR_DECL(struct HPluginPacket) packets[hpPHP_MAX]; /* plugin file ptr caching */ - struct HPMFileNameCache *fnames; - unsigned int fnamec; + struct { + // This doesn't use a VECTOR because it needs to exist after the memory manager goes down. + int count; + struct HPMFileNameCache *data; + } filenames; /* config listen */ struct HPConfListenStorage *confs[HPCT_MAX]; unsigned int confsc[HPCT_MAX]; |