diff --git a/libsepol/src/expand.c b/libsepol/src/expand.c index 0b217491..1b8bef50 100644 --- a/libsepol/src/expand.c +++ b/libsepol/src/expand.c @@ -2032,11 +2032,6 @@ static int ocontext_copy_xen(expand_state_t *state) else state->out->ocontexts[i] = n; l = n; - if (context_copy(&n->context[0], &c->context[0], - state)) { - ERR(state->handle, "Out of memory!"); - return -1; - } switch (i) { case OCON_XEN_ISID: n->sid[0] = c->sid[0]; @@ -2061,6 +2056,11 @@ static int ocontext_copy_xen(expand_state_t *state) ERR(state->handle, "Unknown ocontext"); return -1; } + if (context_copy(&n->context[0], &c->context[0], + state)) { + ERR(state->handle, "Out of memory!"); + return -1; + } } } return 0; @@ -2085,10 +2085,6 @@ static int ocontext_copy_selinux(expand_state_t *state) else state->out->ocontexts[i] = n; l = n; - if (context_copy(&n->context[0], &c->context[0], state)) { - ERR(state->handle, "Out of memory!"); - return -1; - } switch (i) { case OCON_ISID: n->sid[0] = c->sid[0]; @@ -2134,6 +2130,10 @@ static int ocontext_copy_selinux(expand_state_t *state) ERR(state->handle, "Unknown ocontext"); return -1; } + if (context_copy(&n->context[0], &c->context[0], state)) { + ERR(state->handle, "Out of memory!"); + return -1; + } } } return 0;