Skip to content

Commit

Permalink
Fix: lrmd: Avoid memory leak in resources_action_create()
Browse files Browse the repository at this point in the history
  • Loading branch information
beekhof committed Mar 21, 2013
1 parent 48932af commit eff6561
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 12 additions & 5 deletions lib/services/services.c
Expand Up @@ -70,27 +70,27 @@ resources_action_create(const char *name, const char *standard, const char *prov

if (crm_strlen_zero(name)) {
crm_err("A service or resource action must have a name.");
return NULL;
goto return_error;
}

if (crm_strlen_zero(standard)) {
crm_err("A service action must have a valid standard.");
return NULL;
goto return_error;
}

if (!strcasecmp(standard, "ocf") && crm_strlen_zero(provider)) {
crm_err("An OCF resource action must have a provider.");
return NULL;
goto return_error;
}

if (crm_strlen_zero(agent)) {
crm_err("A service or resource action must have an agent.");
return NULL;
goto return_error;
}

if (crm_strlen_zero(action)) {
crm_err("A service or resource action must specify an action.");
return NULL;
goto return_error;
}

if (safe_str_eq(action, "monitor")
Expand Down Expand Up @@ -163,6 +163,7 @@ resources_action_create(const char *name, const char *standard, const char *prov
if (strcasecmp(op->standard, "ocf") == 0) {
op->provider = strdup(provider);
op->params = params;
params = NULL;

if (asprintf(&op->opaque->exec, "%s/resource.d/%s/%s", OCF_ROOT_DIR, provider, agent) == -1) {
goto return_error;
Expand Down Expand Up @@ -253,9 +254,15 @@ resources_action_create(const char *name, const char *standard, const char *prov
op = NULL;
}

if(params) {
g_hash_table_destroy(params);
}
return op;

return_error:
if(params) {
g_hash_table_destroy(params);
}
services_action_free(op);

return NULL;
Expand Down
9 changes: 5 additions & 4 deletions lrmd/lrmd.c
Expand Up @@ -5,12 +5,12 @@
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Expand Down Expand Up @@ -870,10 +870,11 @@ lrmd_rsc_execute_service_lib(lrmd_rsc_t * rsc, lrmd_cmd_t * cmd)

action->cb_data = cmd;

/* 'cmd' may not be valid after this point
/* 'cmd' may not be valid after this point if
* services_action_async() returned TRUE
*
* Upstart and systemd both synchronously determine monitor/status
* results and call action_complete (which may free 'cmd') if necessary
* results and call action_complete (which may free 'cmd') if necessary.
*/
if (services_action_async(action, action_complete)) {
return TRUE;
Expand Down

0 comments on commit eff6561

Please sign in to comment.