Skip to content

Commit

Permalink
Avoid passing huge object by value
Browse files Browse the repository at this point in the history
GLastParse has a size of 4128 bytes, pass by pointer than by value.

Reported-by: coverity
  • Loading branch information
cgzones authored and allinurl committed Jun 1, 2024
1 parent 3ac2198 commit 6c6e7ee
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/gkhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ init_gkhashdb (void) {
* On error, -1 is returned.
* On success 0 is returned */
int
ins_iglp (khash_t (iglp) *hash, uint64_t key, GLastParse lp) {
ins_iglp (khash_t (iglp) *hash, uint64_t key, const GLastParse *lp) {
khint_t k;
int ret;

Expand All @@ -634,7 +634,7 @@ ins_iglp (khash_t (iglp) *hash, uint64_t key, GLastParse lp) {
if (ret == -1)
return -1;

kh_val (hash, k) = lp;
kh_val (hash, k) = *lp;

return 0;
}
Expand Down Expand Up @@ -1497,7 +1497,7 @@ ht_inc_cnt_overall (const char *key, uint32_t val) {
}

int
ht_insert_last_parse (uint64_t key, GLastParse lp) {
ht_insert_last_parse (uint64_t key, const GLastParse *lp) {
GKDB *db = get_db_instance (DB_INSTANCE);
khash_t (iglp) * hash = get_hdb (db, MTRC_LAST_PARSE);

Expand Down
4 changes: 2 additions & 2 deletions src/gkhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void des_u648 (void *h, GO_UNUSED uint8_t free_data);

int inc_iu64 (khash_t (iu64) * hash, uint32_t key, uint64_t inc);
int inc_su64 (khash_t (su64) * hash, const char *key, uint64_t inc);
int ins_iglp (khash_t (iglp) * hash, uint64_t key, GLastParse lp);
int ins_iglp (khash_t (iglp) * hash, uint64_t key, const GLastParse *lp);
int ins_igsl (khash_t (igsl) * hash, uint32_t key, uint32_t value);
int ins_ii08 (khash_t (ii08) * hash, uint32_t key, uint8_t value);
int ins_ii32 (khash_t (ii32) * hash, uint32_t key, uint32_t value);
Expand All @@ -168,7 +168,7 @@ void get_iu64_min_max (khash_t (iu64) * hash, uint64_t * min, uint64_t * max);

int ht_insert_hostname (const char *ip, const char *host);
int ht_insert_json_logfmt (GO_UNUSED void *userdata, char *key, char *spec);
int ht_insert_last_parse (uint64_t key, GLastParse lp);
int ht_insert_last_parse (uint64_t key, const GLastParse *lp);
uint32_t ht_inc_cnt_overall (const char *key, uint32_t val);
uint32_t ht_ins_seq (khash_t (si32) * hash, const char *key);
uint8_t ht_insert_meth_proto (const char *key);
Expand Down
2 changes: 1 addition & 1 deletion src/goaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ perform_tail_follow (GLog *glog) {
if (glog->props.inode) {
glog->lp.line = glog->read;
glog->lp.size = glog->props.size;
ht_insert_last_parse (glog->props.inode, glog->lp);
ht_insert_last_parse (glog->props.inode, &glog->lp);
}

out:
Expand Down
4 changes: 2 additions & 2 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2286,11 +2286,11 @@ persist_last_parse (GLog *glog) {

memcpy (glog->lp.snippet, glog->snippet, glog->snippetlen);

ht_insert_last_parse (glog->props.inode, glog->lp);
ht_insert_last_parse (glog->props.inode, &glog->lp);
}
/* probably from a pipe */
else if (!glog->props.inode) {
ht_insert_last_parse (0, glog->lp);
ht_insert_last_parse (0, &glog->lp);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/persistence.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ restore_global_iglp (khash_t (iglp) *hash, const char *fn) {
tn = tpl_map (fmt, &key, &val, READ_BYTES);
tpl_load (tn, TPL_FILE, fn);
while (tpl_unpack (tn, 1) > 0) {
ins_iglp (hash, key, val);
ins_iglp (hash, key, &val);
}
tpl_free (tn);
}
Expand Down

0 comments on commit 6c6e7ee

Please sign in to comment.