Skip to content

Commit d0c1224

Browse files
authored
Merge pull request #1956 from giuseppe/fix-resource-leak-on-errors
seccomp: fix n_plugins calculation
2 parents 2f2e452 + 899b9fa commit d0c1224

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/libcrun/seccomp_notify.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ libcrun_load_seccomp_notify_plugins (struct seccomp_notify_context_s **out, cons
9595
ctx->sreq = xmalloc (ctx->sizes.seccomp_notif);
9696
ctx->sresp = xmalloc (ctx->sizes.seccomp_notif_resp);
9797

98+
if (is_empty_string (plugins))
99+
return 0;
100+
101+
b = xstrdup (plugins);
102+
98103
ctx->n_plugins = 1;
99-
for (it = b; it; it = strchr (it, ':'))
100-
ctx->n_plugins++;
104+
for (it = b; *it; it++)
105+
if (*it == ':')
106+
ctx->n_plugins++;
101107

102108
ctx->plugins = xmalloc0 (sizeof (struct plugin) * (ctx->n_plugins + 1));
103-
104-
b = xstrdup (plugins);
105109
for (s = 0, it = strtok_r (b, ":", &saveptr); it; s++, it = strtok_r (NULL, ":", &saveptr))
106110
{
107111
run_oci_seccomp_notify_plugin_version_cb version_cb;
@@ -254,6 +258,7 @@ libcrun_free_seccomp_notify_plugins (struct seccomp_notify_context_s *ctx, libcr
254258
dlclose (ctx->plugins[i].handle);
255259
}
256260

261+
free (ctx->plugins);
257262
free (ctx);
258263

259264
return 0;

0 commit comments

Comments
 (0)