Skip to content

Commit 4640465

Browse files
committed
[WIP] statistics: fix crash when creating a series stat
Under normal circumstances, when a statistic is updated, we first search whether it exists, and if not, we add it to the statistics hash. However, due to the way it is implemented, searching and adding a statistic is not atomic, hence, with high concurrency, when adding a new statistic, we might already find an existing one there. In this case, the code tries to return that statistic in the `pvar` parameter - however, that parameter might be a (r/o) function, hence a crash happens. This commit fixes the crash. Close OpenSIPS#3136 However, it returns 0, as if the statistic was properly added - the problem with this approach is that from the caller's perspective, we do not know whether the statistic was already there or not, to free the existing structure - hence this might result into a leak. We are still working on a solution for this.
1 parent 41aa549 commit 4640465

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

statistics.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ static int __register_stat(str *module, str *name, stat_var **pvar,
521521
shm_free(stat);
522522
}
523523

524-
*pvar = it;
524+
if ((flags&STAT_IS_FUNC)==0)
525+
*pvar = it;
525526
return 0;
526527
}
527528
}

0 commit comments

Comments
 (0)