Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix: lrmd: Avoid memory leak in resources_action_create()

  • Loading branch information...
commit eff656103dad5bce0964a77debcbfd1dcf53bc76 1 parent 48932af
Andrew Beekhof authored

Showing 2 changed files with 17 additions and 9 deletions. Show diff stats Hide diff stats

  1. +12 5 lib/services/services.c
  2. +5 4 lrmd/lrmd.c
17 lib/services/services.c
@@ -70,27 +70,27 @@ resources_action_create(const char *name, const char *standard, const char *prov
70 70
71 71 if (crm_strlen_zero(name)) {
72 72 crm_err("A service or resource action must have a name.");
73   - return NULL;
  73 + goto return_error;
74 74 }
75 75
76 76 if (crm_strlen_zero(standard)) {
77 77 crm_err("A service action must have a valid standard.");
78   - return NULL;
  78 + goto return_error;
79 79 }
80 80
81 81 if (!strcasecmp(standard, "ocf") && crm_strlen_zero(provider)) {
82 82 crm_err("An OCF resource action must have a provider.");
83   - return NULL;
  83 + goto return_error;
84 84 }
85 85
86 86 if (crm_strlen_zero(agent)) {
87 87 crm_err("A service or resource action must have an agent.");
88   - return NULL;
  88 + goto return_error;
89 89 }
90 90
91 91 if (crm_strlen_zero(action)) {
92 92 crm_err("A service or resource action must specify an action.");
93   - return NULL;
  93 + goto return_error;
94 94 }
95 95
96 96 if (safe_str_eq(action, "monitor")
@@ -163,6 +163,7 @@ resources_action_create(const char *name, const char *standard, const char *prov
163 163 if (strcasecmp(op->standard, "ocf") == 0) {
164 164 op->provider = strdup(provider);
165 165 op->params = params;
  166 + params = NULL;
166 167
167 168 if (asprintf(&op->opaque->exec, "%s/resource.d/%s/%s", OCF_ROOT_DIR, provider, agent) == -1) {
168 169 goto return_error;
@@ -253,9 +254,15 @@ resources_action_create(const char *name, const char *standard, const char *prov
253 254 op = NULL;
254 255 }
255 256
  257 + if(params) {
  258 + g_hash_table_destroy(params);
  259 + }
256 260 return op;
257 261
258 262 return_error:
  263 + if(params) {
  264 + g_hash_table_destroy(params);
  265 + }
259 266 services_action_free(op);
260 267
261 268 return NULL;
9 lrmd/lrmd.c
@@ -5,12 +5,12 @@
5 5 * modify it under the terms of the GNU Lesser General Public
6 6 * License as published by the Free Software Foundation; either
7 7 * version 2.1 of the License, or (at your option) any later version.
8   - *
  8 + *
9 9 * This library is distributed in the hope that it will be useful,
10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 12 * Lesser General Public License for more details.
13   - *
  13 + *
14 14 * You should have received a copy of the GNU Lesser General Public
15 15 * License along with this library; if not, write to the Free Software
16 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -870,10 +870,11 @@ lrmd_rsc_execute_service_lib(lrmd_rsc_t * rsc, lrmd_cmd_t * cmd)
870 870
871 871 action->cb_data = cmd;
872 872
873   - /* 'cmd' may not be valid after this point
  873 + /* 'cmd' may not be valid after this point if
  874 + * services_action_async() returned TRUE
874 875 *
875 876 * Upstart and systemd both synchronously determine monitor/status
876   - * results and call action_complete (which may free 'cmd') if necessary
  877 + * results and call action_complete (which may free 'cmd') if necessary.
877 878 */
878 879 if (services_action_async(action, action_complete)) {
879 880 return TRUE;

0 comments on commit eff6561

Please sign in to comment.
Something went wrong with that request. Please try again.