* [ libsepol 1/6] Fix memory leaks
@ 2005-07-21 17:36 Ivan Gyurdiev
2005-07-21 18:36 ` Joshua Brindle
0 siblings, 1 reply; 3+ messages in thread
From: Ivan Gyurdiev @ 2005-07-21 17:36 UTC (permalink / raw)
To: selinux
[-- Attachment #1: Type: text/plain, Size: 226 bytes --]
The following patch fixes memory leaks.
The ones in policydb_convert are due to double
initialization (policydb_read does its own init).
libsepol-1.2-fix_memory_leaks.diff
This patch depends on
libsepol-1.1-context.diff
[-- Attachment #2: libsepol-1.2-fix_memory_leaks.diff --]
[-- Type: text/x-patch, Size: 3724 bytes --]
diff -aru libsepol.work/src/constraint.c libsepol-1.2-fix_memory_leaks/src/constraint.c
--- libsepol.work/src/constraint.c 2005-07-18 15:05:30.000000000 -0400
+++ libsepol-1.2-fix_memory_leaks/src/constraint.c 2005-07-21 10:58:05.000000000 -0400
@@ -30,6 +30,7 @@
if (expr != NULL) {
ebitmap_destroy(&expr->names);
type_set_destroy(expr->type_names);
+ free(expr->type_names);
free(expr);
}
}
diff -aru libsepol.work/src/policydb.c libsepol-1.2-fix_memory_leaks/src/policydb.c
--- libsepol.work/src/policydb.c 2005-07-21 13:06:49.000000000 -0400
+++ libsepol-1.2-fix_memory_leaks/src/policydb.c 2005-07-21 10:58:05.000000000 -0400
@@ -870,6 +870,8 @@
free(p->role_val_to_struct);
if (p->user_val_to_struct)
free(p->user_val_to_struct);
+ if (p->type_val_to_struct)
+ free(p->type_val_to_struct);
for (i = 0; i < SYM_NUM; i++) {
hashtab_map(p->scope[i].table, scope_destroy, 0);
@@ -945,6 +947,7 @@
if (cur != NULL) {
free (cur->decl_ids);
}
+ free(cur);
return 0;
}
@@ -1266,8 +1269,10 @@
depth++;
break;
case CEXPR_NAMES:
- if (!allowxtarget && (e->attr & CEXPR_XTARGET))
+ if (!allowxtarget && (e->attr & CEXPR_XTARGET)) {
+ constraint_expr_destroy(e);
return -1;
+ }
if (depth == (CEXPR_MAXDEPTH-1)) {
constraint_expr_destroy(e);
return -1;
diff -aru libsepol.work/src/policydb_convert.c libsepol-1.2-fix_memory_leaks/src/policydb_convert.c
--- libsepol.work/src/policydb_convert.c 2005-07-18 15:05:30.000000000 -0400
+++ libsepol-1.2-fix_memory_leaks/src/policydb_convert.c 2005-07-21 11:41:52.000000000 -0400
@@ -34,10 +34,6 @@
policy_file_t pf;
struct policydb tmp_policydb;
- if (policydb_init(&tmp_policydb, POLICY_KERN) < 0) {
- DEBUG(__FUNCTION__, "could not initialize temporary policy\n");
- goto err;
- }
/* Set the policy version for the new policy image we are
about to generate so that it stays the same as the original,
even if we support a newer one. */
@@ -50,7 +46,7 @@
if (policydb_write(policydb, &pf)) {
DEBUG(__FUNCTION__, "could not compute policy length\n");
errno = EINVAL;
- goto err_free;
+ goto err;
}
/* Allocate the new policy image. */
@@ -58,7 +54,7 @@
pf.data = malloc(pf.len);
if (!pf.data) {
DEBUG(__FUNCTION__, "out of memory\n");
- goto err_free;
+ goto err;
}
/* Need to save len and data prior to modification by policydb_write.*/
@@ -69,7 +65,7 @@
if (policydb_write(policydb, &pf)) {
DEBUG(__FUNCTION__, "could not write policy\n");
errno = EINVAL;
- goto err_free;
+ goto err;
}
/* Verify the new policy image. */
@@ -79,7 +75,7 @@
if (policydb_read(&tmp_policydb, &pf, 0)) {
DEBUG(__FUNCTION__, "new policy image is invalid\n");
errno = EINVAL;
- goto err_free;
+ goto err;
}
policydb_destroy(&tmp_policydb);
@@ -91,9 +87,6 @@
sepol_set_policyvers(POLICY_KERN, POLICYDB_VERSION_MAX);
return STATUS_SUCCESS;
- err_free:
- policydb_destroy(&tmp_policydb);
-
err:
DEBUG(__FUNCTION__, "could not create policy image\n");
diff -aru libsepol.work/src/util.c libsepol-1.2-fix_memory_leaks/src/util.c
--- libsepol.work/src/util.c 2005-07-18 15:05:30.000000000 -0400
+++ libsepol-1.2-fix_memory_leaks/src/util.c 2005-07-21 10:39:55.000000000 -0400
@@ -192,6 +192,7 @@
scope_datum->decl_ids = NULL;
scope_datum->decl_ids_len = 0;
if ((rc = hashtab_insert(pol->scope[sym].table, key, scope_datum)) != 0) {
+ free(scope_datum);
return rc;
}
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [ libsepol 1/6] Fix memory leaks
2005-07-21 17:36 [ libsepol 1/6] Fix memory leaks Ivan Gyurdiev
@ 2005-07-21 18:36 ` Joshua Brindle
2005-07-21 18:37 ` Ivan Gyurdiev
0 siblings, 1 reply; 3+ messages in thread
From: Joshua Brindle @ 2005-07-21 18:36 UTC (permalink / raw)
To: gyurdiev; +Cc: selinux
Ivan Gyurdiev wrote:
>The following patch fixes memory leaks.
>The ones in policydb_convert are due to double
>initialization (policydb_read does its own init).
>
>libsepol-1.2-fix_memory_leaks.diff
>
>This patch depends on
>libsepol-1.1-context.diff
>
>
>
adding the -p flag to diff would be very helpful
I'm not sure where these frees are being added to I can't tell if they
are correct
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [ libsepol 1/6] Fix memory leaks
2005-07-21 18:36 ` Joshua Brindle
@ 2005-07-21 18:37 ` Ivan Gyurdiev
0 siblings, 0 replies; 3+ messages in thread
From: Ivan Gyurdiev @ 2005-07-21 18:37 UTC (permalink / raw)
To: Joshua Brindle; +Cc: selinux
[-- Attachment #1: Type: text/plain, Size: 185 bytes --]
> adding the -p flag to diff would be very helpful
>
> I'm not sure where these frees are being added to I can't tell if they
> are correct
Attached is a version with the -p flag
[-- Attachment #2: libsepol-1.2-fix_memory_leaks.diff --]
[-- Type: text/x-patch, Size: 4076 bytes --]
diff -p -aru libsepol.work/src/constraint.c libsepol-1.2-fix_memory_leaks/src/constraint.c
--- libsepol.work/src/constraint.c 2005-07-18 15:05:30.000000000 -0400
+++ libsepol-1.2-fix_memory_leaks/src/constraint.c 2005-07-21 10:58:05.000000000 -0400
@@ -30,6 +30,7 @@ void constraint_expr_destroy(constraint_
if (expr != NULL) {
ebitmap_destroy(&expr->names);
type_set_destroy(expr->type_names);
+ free(expr->type_names);
free(expr);
}
}
diff -p -aru libsepol.work/src/policydb.c libsepol-1.2-fix_memory_leaks/src/policydb.c
--- libsepol.work/src/policydb.c 2005-07-21 14:35:49.000000000 -0400
+++ libsepol-1.2-fix_memory_leaks/src/policydb.c 2005-07-21 10:58:05.000000000 -0400
@@ -870,6 +870,8 @@ void policydb_destroy(policydb_t * p)
free(p->role_val_to_struct);
if (p->user_val_to_struct)
free(p->user_val_to_struct);
+ if (p->type_val_to_struct)
+ free(p->type_val_to_struct);
for (i = 0; i < SYM_NUM; i++) {
hashtab_map(p->scope[i].table, scope_destroy, 0);
@@ -945,6 +947,7 @@ int scope_destroy(hashtab_key_t key, has
if (cur != NULL) {
free (cur->decl_ids);
}
+ free(cur);
return 0;
}
@@ -1266,8 +1269,10 @@ static int read_cons_helper(policydb_t *
depth++;
break;
case CEXPR_NAMES:
- if (!allowxtarget && (e->attr & CEXPR_XTARGET))
+ if (!allowxtarget && (e->attr & CEXPR_XTARGET)) {
+ constraint_expr_destroy(e);
return -1;
+ }
if (depth == (CEXPR_MAXDEPTH-1)) {
constraint_expr_destroy(e);
return -1;
diff -p -aru libsepol.work/src/policydb_convert.c libsepol-1.2-fix_memory_leaks/src/policydb_convert.c
--- libsepol.work/src/policydb_convert.c 2005-07-18 15:05:30.000000000 -0400
+++ libsepol-1.2-fix_memory_leaks/src/policydb_convert.c 2005-07-21 11:41:52.000000000 -0400
@@ -34,10 +34,6 @@ int policydb_to_image(
policy_file_t pf;
struct policydb tmp_policydb;
- if (policydb_init(&tmp_policydb, POLICY_KERN) < 0) {
- DEBUG(__FUNCTION__, "could not initialize temporary policy\n");
- goto err;
- }
/* Set the policy version for the new policy image we are
about to generate so that it stays the same as the original,
even if we support a newer one. */
@@ -50,7 +46,7 @@ int policydb_to_image(
if (policydb_write(policydb, &pf)) {
DEBUG(__FUNCTION__, "could not compute policy length\n");
errno = EINVAL;
- goto err_free;
+ goto err;
}
/* Allocate the new policy image. */
@@ -58,7 +54,7 @@ int policydb_to_image(
pf.data = malloc(pf.len);
if (!pf.data) {
DEBUG(__FUNCTION__, "out of memory\n");
- goto err_free;
+ goto err;
}
/* Need to save len and data prior to modification by policydb_write.*/
@@ -69,7 +65,7 @@ int policydb_to_image(
if (policydb_write(policydb, &pf)) {
DEBUG(__FUNCTION__, "could not write policy\n");
errno = EINVAL;
- goto err_free;
+ goto err;
}
/* Verify the new policy image. */
@@ -79,7 +75,7 @@ int policydb_to_image(
if (policydb_read(&tmp_policydb, &pf, 0)) {
DEBUG(__FUNCTION__, "new policy image is invalid\n");
errno = EINVAL;
- goto err_free;
+ goto err;
}
policydb_destroy(&tmp_policydb);
@@ -91,9 +87,6 @@ int policydb_to_image(
sepol_set_policyvers(POLICY_KERN, POLICYDB_VERSION_MAX);
return STATUS_SUCCESS;
- err_free:
- policydb_destroy(&tmp_policydb);
-
err:
DEBUG(__FUNCTION__, "could not create policy image\n");
diff -p -aru libsepol.work/src/util.c libsepol-1.2-fix_memory_leaks/src/util.c
--- libsepol.work/src/util.c 2005-07-18 15:05:30.000000000 -0400
+++ libsepol-1.2-fix_memory_leaks/src/util.c 2005-07-21 10:39:55.000000000 -0400
@@ -192,6 +192,7 @@ int symtab_insert(policydb_t *pol, uint3
scope_datum->decl_ids = NULL;
scope_datum->decl_ids_len = 0;
if ((rc = hashtab_insert(pol->scope[sym].table, key, scope_datum)) != 0) {
+ free(scope_datum);
return rc;
}
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-07-21 18:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-21 17:36 [ libsepol 1/6] Fix memory leaks Ivan Gyurdiev
2005-07-21 18:36 ` Joshua Brindle
2005-07-21 18:37 ` Ivan Gyurdiev
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.