Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-11470

function expand_trigger_description_constants() performs unnecessary allocations

XMLWordPrintable

    • Sprint 1, Sprint 2, Sprint 3
    • 5

      We have the following function in src/libs/zbxserver/expression.c:

      /******************************************************************************
       *                                                                            *
       * Function: expand_trigger_description_constants                             *
       *                                                                            *
       * Purpose: substitute simple macros in data string with real values          *
       *                                                                            *
       * Parameters: data - trigger description                                     *
       *                                                                            *
       ******************************************************************************/
      static void	expand_trigger_description_constants(char **data, const char *expression)
      {
      	char	**numbers = NULL, *new_str = NULL, replace[3] = "$0";
      	int	numbers_cnt = 0, i = 0;
      
      	numbers = extract_numbers(expression, &numbers_cnt);
      
      	for (i = 0; i < 9; i++)
      	{
      		replace[1] = '0' + i + 1;
      		new_str = string_replace(*data, replace, i < numbers_cnt ?  numbers[i] : "");
      		zbx_free(*data);
      		*data = new_str;
      	}
      
      	zbx_free_numbers(&numbers, numbers_cnt);
      }
      

      It seems to perform at least 10 string allocations, even if they are not required. This should be optimized.

            Unassigned Unassigned
            asaveljevs Aleksandrs Saveljevs
            Team A
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: