Merge lp:~gl-az/percona-server/BT-23597-bug1166638-5.6 into lp:percona-server/5.6

Proposed by George Ormond Lorch III
Status: Merged
Approved by: Laurynas Biveinis
Approved revision: no longer in the source branch.
Merged at revision: 439
Proposed branch: lp:~gl-az/percona-server/BT-23597-bug1166638-5.6
Merge into: lp:percona-server/5.6
Diff against target: 133 lines (+46/-15)
1 file modified
Percona-Server/sql/sql_acl.cc (+46/-15)
To merge this branch: bzr merge lp:~gl-az/percona-server/BT-23597-bug1166638-5.6
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Approve
Review via email: mp+187901@code.launchpad.net

Description of the change

Merged from 5.5:
Fix for https://bugs.launchpad.net/percona-server/+bug/1166638 - Utility user setup leaks memory | Valgrind: still reachable: malloc in acl_init_utility_user & init_dynamic_array2

Originally this was just written off as a known, one time leak, which is is, but the failure causes scripted testing to fail and is really just sloppy.

To fix, created new status flags that indicate whather or not acl_utility_user and acl_utility_user_schema_access have been initialized. Create new function to clean up utility user resources and call it from acl_free and from acl_init_utility_user to free up if being reinitialized or if there is an error during the initialization. For 5.6 had to move some things around due to the struct++'ing that upstream devs did (turning structs into classes without properly building out rational/smart class interfaces for data access and management).

http://jenkins.percona.com/view/PS%205.6/job/percona-server-5.6-param/319/

To post a comment you must log in.
Revision history for this message
George Ormond Lorch III (gl-az) wrote :
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

- Same comment as in 5.5 re. acl_free_utility_user() header comment.
- Any reason 5.6 acl_free_utility_user() does not bzero acl_utility_user like 5.5 does?

review: Needs Information
Revision history for this message
George Ormond Lorch III (gl-az) wrote :

On 9/29/2013 2:04 AM, Laurynas Biveinis wrote:
> Review: Needs Information
>
> - Same comment as in 5.5 re. acl_free_utility_user() header comment.
> - Any reason 5.6 acl_free_utility_user() does not bzero acl_utility_user like 5.5 does?
>
in 5.6 ACL_USER is a class with private members, 5.5 it is just a
struct...the 5.6 struct++ization of the codebase isn't very friendly to
bzeroing of things :)

--
George O. Lorch III
Software Engineer, Percona
+1-888-401-3401 x542 US/Arizona (GMT -7)
skype: george.ormond.lorch.iii

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

I think that ACL_USER satisfies C++ POD requirements and is thus safe to memset/memcpy, but still OK to leave this out if you prefer.

Revision history for this message
George Ormond Lorch III (gl-az) wrote :

Fixed acl_free_utility_user comment and went ahead and added back on memset (in place of 5.5 bzero).

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Percona-Server/sql/sql_acl.cc'
--- Percona-Server/sql/sql_acl.cc 2013-08-27 20:55:20 +0000
+++ Percona-Server/sql/sql_acl.cc 2013-09-30 17:15:58 +0000
@@ -891,8 +891,11 @@
891};891};
892892
893static ACL_USER acl_utility_user;893static ACL_USER acl_utility_user;
894LEX_STRING acl_utility_user_name, acl_utility_user_host_name;
894static DYNAMIC_ARRAY acl_utility_user_schema_access;895static DYNAMIC_ARRAY acl_utility_user_schema_access;
896static bool acl_utility_user_initialized= false;
895static my_bool acl_init_utility_user(my_bool check_no_resolve);897static my_bool acl_init_utility_user(my_bool check_no_resolve);
898static void acl_free_utility_user();
896899
897/**900/**
898 Convert scrambled password to binary form, according to scramble type, 901 Convert scrambled password to binary form, according to scramble type,
@@ -1462,6 +1465,7 @@
14621465
1463void acl_free(bool end)1466void acl_free(bool end)
1464{1467{
1468 acl_free_utility_user();
1465 free_root(&global_acl_memory,MYF(0));1469 free_root(&global_acl_memory,MYF(0));
1466 delete_dynamic(&acl_users);1470 delete_dynamic(&acl_users);
1467 delete_dynamic(&acl_dbs);1471 delete_dynamic(&acl_dbs);
@@ -1652,7 +1656,6 @@
1652my_bool1656my_bool
1653acl_init_utility_user(my_bool check_no_resolve)1657acl_init_utility_user(my_bool check_no_resolve)
1654{1658{
1655 LEX_STRING acl_user_name, acl_host_name;
1656 char password[CRYPT_MAX_PASSWORD_SIZE + 1];1659 char password[CRYPT_MAX_PASSWORD_SIZE + 1];
1657 uint i, passlen;1660 uint i, passlen;
1658 my_bool ret= TRUE;1661 my_bool ret= TRUE;
@@ -1660,15 +1663,23 @@
1660 if (!utility_user)1663 if (!utility_user)
1661 goto end;1664 goto end;
16621665
1666 acl_free_utility_user();
1667
1668 /* Allocate all initial resources necessary */
1669 acl_utility_user_name.str= (char *) my_malloc(USERNAME_LENGTH+1, MY_ZEROFILL);
1670 acl_utility_user_host_name.str= (char *) my_malloc(HOSTNAME_LENGTH+1, MY_ZEROFILL);
1671 (void) my_init_dynamic_array(&acl_utility_user_schema_access, sizeof(char *),
1672 5, 10);
1673 acl_utility_user_initialized= true;
1674
1663 /* parse out the option to its component user and host name parts */1675 /* parse out the option to its component user and host name parts */
1664 acl_user_name.str= (char *) my_malloc(USERNAME_LENGTH+1, MY_ZEROFILL);
1665 acl_host_name.str= (char *) my_malloc(HOSTNAME_LENGTH+1, MY_ZEROFILL);
1666 parse_user(utility_user, strlen(utility_user),1676 parse_user(utility_user, strlen(utility_user),
1667 acl_user_name.str, &acl_user_name.length,1677 acl_utility_user_name.str, &acl_utility_user_name.length,
1668 acl_host_name.str, &acl_host_name.length);1678 acl_utility_user_host_name.str,
1679 &acl_utility_user_host_name.length);
16691680
1670 /* Check to see if the username is anonymous */1681 /* Check to see if the username is anonymous */
1671 if (!acl_user_name.str || acl_user_name.str[0] == '\0')1682 if (!acl_utility_user_name.str || acl_utility_user_name.str[0] == '\0')
1672 {1683 {
1673 sql_print_error("'utility user' specified as '%s' is anonymous"1684 sql_print_error("'utility user' specified as '%s' is anonymous"
1674 " and not allowed.",1685 " and not allowed.",
@@ -1688,9 +1699,9 @@
1688 }1699 }
16891700
1690 /* set up some of the static utility user struct fields */1701 /* set up some of the static utility user struct fields */
1691 acl_utility_user.user= acl_user_name.str;1702 acl_utility_user.user= acl_utility_user_name.str;
16921703
1693 acl_utility_user.host.update_hostname(acl_host_name.str);1704 acl_utility_user.host.update_hostname(acl_utility_user_host_name.str);
16941705
1695 acl_utility_user.sort= get_sort(2, acl_utility_user.host.get_host(),1706 acl_utility_user.sort= get_sort(2, acl_utility_user.host.get_host(),
1696 acl_utility_user.user);1707 acl_utility_user.user);
@@ -1700,7 +1711,7 @@
1700 {1711 {
1701 ACL_USER *user= dynamic_element(&acl_users, i, ACL_USER*);1712 ACL_USER *user= dynamic_element(&acl_users, i, ACL_USER*);
1702 if (user->user1713 if (user->user
1703 && strcmp(acl_user_name.str, user->user) == 0)1714 && strcmp(acl_utility_user_name.str, user->user) == 0)
1704 {1715 {
1705 if (user->sort == acl_utility_user.sort)1716 if (user->sort == acl_utility_user.sort)
1706 {1717 {
@@ -1774,9 +1785,6 @@
1774 (void) push_dynamic(&acl_users,(uchar*) &acl_utility_user);1785 (void) push_dynamic(&acl_users,(uchar*) &acl_utility_user);
1775 1786
1776 /* initialize the schema access list if specified */1787 /* initialize the schema access list if specified */
1777 (void) my_init_dynamic_array(&acl_utility_user_schema_access, sizeof(char *),
1778 5, 10);
1779
1780 if (utility_user_schema_access)1788 if (utility_user_schema_access)
1781 {1789 {
1782 char *cur_pos= utility_user_schema_access;1790 char *cur_pos= utility_user_schema_access;
@@ -1810,15 +1818,38 @@
1810 goto end;1818 goto end;
18111819
1812cleanup:1820cleanup:
1813 my_free(acl_user_name.str);1821 acl_free_utility_user();
1814 my_free(acl_host_name.str);
1815 memset(&acl_utility_user, 0, sizeof(acl_utility_user));
18161822
1817end:1823end:
1818 return ret;1824 return ret;
1819}1825}
18201826
1821/*1827/*
1828 Free up any resources allocated during acl_init_utility_user.
1829*/
1830static
1831void
1832acl_free_utility_user()
1833{
1834 if (acl_utility_user_initialized)
1835 {
1836 uint i;
1837 for (i=0 ; i < acl_utility_user_schema_access.elements ; i++)
1838 {
1839 char** dbname= dynamic_element(&acl_utility_user_schema_access, i, char**);
1840 if (*dbname)
1841 my_free(*dbname);
1842 }
1843 delete_dynamic(&acl_utility_user_schema_access);
1844
1845 my_free(acl_utility_user_name.str);
1846 my_free(acl_utility_user_host_name.str);
1847 memset(&acl_utility_user, 0, sizeof(acl_utility_user));
1848 acl_utility_user_initialized= false;
1849 }
1850}
1851
1852/*
1822 Determines if the user specified by user, host, ip matches the utility user1853 Determines if the user specified by user, host, ip matches the utility user
1823*/1854*/
1824my_bool1855my_bool

Subscribers

People subscribed via source and target branches