From afffa6e9b45cbe9b33943e26568d8ac69b899252 Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Sun, 18 Aug 2013 01:06:16 +0200 Subject: 4062 libscf: memory leaks in scf_simple_app_props_get() Reviewed by: Jeffry Molanus Reviewed by: Boris Protopopov Reviewed by: Andy Stormont Approved by: Dan McDonald --- usr/src/lib/libscf/common/midlevel.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'usr/src/lib/libscf/common/midlevel.c') diff --git a/usr/src/lib/libscf/common/midlevel.c b/usr/src/lib/libscf/common/midlevel.c index 71b72404f1..3037e85113 100644 --- a/usr/src/lib/libscf/common/midlevel.c +++ b/usr/src/lib/libscf/common/midlevel.c @@ -21,6 +21,7 @@ /* * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2013 Nexenta Systems, Inc. All rights reserved. */ #include "libscf_impl.h" @@ -1842,11 +1843,14 @@ scf_simple_app_props_get(scf_handle_t *hin, const char *inst_fmri) (pgiter = scf_iter_create(h)) == NULL || (propiter = scf_iter_create(h)) == NULL || (pg = scf_pg_create(h)) == NULL || - (prop = scf_property_create(h)) == NULL) + (prop = scf_property_create(h)) == NULL) { + free(sys_fmri); goto error2; + } if (scf_handle_decode_fmri(h, sys_fmri, NULL, svc, inst, NULL, NULL, SCF_DECODE_FMRI_REQUIRE_INSTANCE) == -1) { + free(sys_fmri); if (scf_error() == SCF_ERROR_CONSTRAINT_VIOLATED) (void) scf_set_error(SCF_ERROR_INVALID_ARGUMENT); goto error2; @@ -1858,6 +1862,7 @@ scf_simple_app_props_get(scf_handle_t *hin, const char *inst_fmri) (pgname = malloc(namelen)) == NULL) { free(thispg); free(ret); + free(sys_fmri); (void) scf_set_error(SCF_ERROR_NO_MEMORY); goto error2; } @@ -2088,6 +2093,9 @@ scf_simple_app_props_get(scf_handle_t *hin, const char *inst_fmri) goto error1; } + if (ret->ap_pglist->pg_name == NULL) + goto error1; + scf_iter_destroy(pgiter); scf_iter_destroy(propiter); scf_pg_destroy(pg); @@ -2099,9 +2107,6 @@ scf_simple_app_props_get(scf_handle_t *hin, const char *inst_fmri) if (local_h) scf_handle_destroy(h); - if (ret->ap_pglist->pg_name == NULL) - return (NULL); - return (ret); /* -- cgit v1.2.3