Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: valgrind: definitely lost: 21 bytes in 1 blocks #60

Closed
shangyanwen opened this issue Jun 20, 2022 · 1 comment
Closed

bug: valgrind: definitely lost: 21 bytes in 1 blocks #60

shangyanwen opened this issue Jun 20, 2022 · 1 comment
Assignees
Labels
A-bug Something isn't working B-robustness Improve stonedb robustness

Comments

@shangyanwen
Copy link
Contributor

Describe the problem

【error】definitely lost: 21 bytes in 1 blocks
【error promot】21 bytes in 1 blocks are definitely lost in loss record 5 of 316
at 0x484147B: calloc (vg_replace_malloc.c:1328)
by 0xBFECE9: my_malloc (my_malloc.c:38)
by 0xE1A368: add_pfs_instr_to_array(char const*, char const*) (pfs_server.cc:251)
by 0x897A8B: mysqld_get_one_option (mysqld.cc:8792)
by 0xC0FE1C: my_handle_options (my_getopt.cc:613)
by 0x89AA85: handle_early_options() (mysqld.cc:6881)
by 0x89FC72: mysqld_main(int, char**) (mysqld.cc:5272)
by 0x4B22082: (below main) (libc-start.c:308)

Expected behavior

no definitely lost
How To Reproduce

1、create database tpch;
2、use tpch;
3、create table,example:
CREATE TABLE NATION  ( 
N_NATIONKEY  INTEGER NOT NULL,
N_NAME       CHAR(25) NOT NULL,
N_REGIONKEY  INTEGER NOT NULL,
N_COMMENT    VARCHAR(152),
primary key (n_nationkey)
);

Environment

1、Ubuntu 20.04.4
2、valgrind-3.19.0
Additional context

no

@shangyanwen shangyanwen added the A-bug Something isn't working label Jun 20, 2022
@shangyanwen shangyanwen changed the title bug: bug: definitely lost: 21 bytes in 1 blocks Jun 20, 2022
@RingsC RingsC changed the title bug: definitely lost: 21 bytes in 1 blocks bug: valgrind: definitely lost: 21 bytes in 1 blocks Jun 20, 2022
@RingsC RingsC added the B-robustness Improve stonedb robustness label Jun 20, 2022
@konghaiya
Copy link
Collaborator

konghaiya commented Jun 28, 2022

"add_ pfs_ instr_ to_ array" function code:

int add_pfs_instr_to_array(const char* name, const char* value)
{
  int name_length= strlen(name);
  int value_length= strlen(value);

  /* Allocate structure plus string buffers plus null terminators */
  PFS_instr_config* e = (PFS_instr_config*)my_malloc(sizeof(PFS_instr_config)
                       + name_length + 1 + value_length + 1, MYF(MY_WME));
  if (!e) return 1;
  
  /* Copy the instrument name */
  e->m_name= (char*)e + sizeof(PFS_instr_config);
  memcpy(e->m_name, name, name_length);
  e->m_name_length= name_length;
  e->m_name[name_length]= '\0';
  
  /* Set flags accordingly */
  if (!my_strcasecmp(&my_charset_latin1, value, "counted"))
  {
    e->m_enabled= true;
    e->m_timed= false;
  }
  else
  if (!my_strcasecmp(&my_charset_latin1, value, "true") ||
      !my_strcasecmp(&my_charset_latin1, value, "on") ||
      !my_strcasecmp(&my_charset_latin1, value, "1") ||
      !my_strcasecmp(&my_charset_latin1, value, "yes"))
  {
    e->m_enabled= true;
    e->m_timed= true;
  }
  else
  if (!my_strcasecmp(&my_charset_latin1, value, "false") ||
      !my_strcasecmp(&my_charset_latin1, value, "off") ||
      !my_strcasecmp(&my_charset_latin1, value, "0") ||
      !my_strcasecmp(&my_charset_latin1, value, "no"))
  {
    e->m_enabled= false;
    e->m_timed= false;
  }
  else
  {
    my_free(e);
    return 1;
  }

  /* Add to the array of default startup options */
  if (insert_dynamic(&pfs_instr_config_array, &e))  //When a problem occurs, the insert succeeds and returns false, resulting in no free
  {
    my_free(e);
    return 1;
  }

  return 0;
}

In "insert_dynamic "function, the" memcpy "is used to insert" element "into" buffer "instead of direct address passing. The successful insertion returns false, resulting in no free for" element ".

Optimization scheme: Increase the release of local dynamic variables regardless of the success of "insert_dynamic".

int add_pfs_instr_to_array(const char* name, const char* value)
{
  int name_length= strlen(name);
  int value_length= strlen(value);

  /* Allocate structure plus string buffers plus null terminators */
  PFS_instr_config* e = (PFS_instr_config*)my_malloc(sizeof(PFS_instr_config)
                       + name_length + 1 + value_length + 1, MYF(MY_WME));
  if (!e) return 1;
  
  /* Copy the instrument name */
  e->m_name= (char*)e + sizeof(PFS_instr_config);
  memcpy(e->m_name, name, name_length);
  e->m_name_length= name_length;
  e->m_name[name_length]= '\0';
  
  /* Set flags accordingly */
  if (!my_strcasecmp(&my_charset_latin1, value, "counted"))
  {
    e->m_enabled= true;
    e->m_timed= false;
  }
  else
  if (!my_strcasecmp(&my_charset_latin1, value, "true") ||
      !my_strcasecmp(&my_charset_latin1, value, "on") ||
      !my_strcasecmp(&my_charset_latin1, value, "1") ||
      !my_strcasecmp(&my_charset_latin1, value, "yes"))
  {
    e->m_enabled= true;
    e->m_timed= true;
  }
  else
  if (!my_strcasecmp(&my_charset_latin1, value, "false") ||
      !my_strcasecmp(&my_charset_latin1, value, "off") ||
      !my_strcasecmp(&my_charset_latin1, value, "0") ||
      !my_strcasecmp(&my_charset_latin1, value, "no"))
  {
    e->m_enabled= false;
    e->m_timed= false;
  }
  else
  {
    my_free(e);
    return 1;
  }

  /* Add to the array of default startup options */
  if (insert_dynamic(&pfs_instr_config_array, &e))  //When a problem occurs, the insert succeeds and returns false, resulting in no free
  {
    my_free(e);
    return 1;
  }
  my_free(e); //Increase the release of local dynamic variables regardless of the success of "insert_dynamic"
  return 0;
}

RingsC pushed a commit that referenced this issue Jul 2, 2022
* fix(stonedb) Valgrind:definitely lost(#60)(#66) and Invalid write、Invalid read(#110)(#108)(#81)(#80) and still reachable(#67)
@konghaiya konghaiya added this to the stonedb_5.6_v1.0.1 milestone Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bug Something isn't working B-robustness Improve stonedb robustness
Projects
None yet
Development

No branches or pull requests

3 participants