Skip to content

Commit

Permalink
launch/service: fix release of argv array
Browse files Browse the repository at this point in the history
While service_free() correctly releases the strv in `argv`, the
service_update() path does not. It frees `argv`, but not the individual
entries. Fix this and properly release all entries.

Reported-by: Evgeny Vereshchagin
Signed-off-by: David Rheinsberg <[email protected]>
  • Loading branch information
dvdhrm committed May 12, 2022
1 parent 608b259 commit 6d9b817
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/launch/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ Service *service_free(Service *service) {
}

int service_update(Service *service, const char *path, const char *unit, size_t argc, char **argv, const char *user, uid_t uid) {
size_t i;

service->path = c_free(service->path);
service->unit = c_free(service->unit);
for (i = 0; i < service->argc; ++i)
free(service->argv[i]);
service->argc = 0;
service->argv = c_free(service->argv);
service->user = c_free(service->user);
Expand All @@ -124,7 +128,7 @@ int service_update(Service *service, const char *path, const char *unit, size_t

service->argc = argc;

for (size_t i = 0; i < argc; ++i) {
for (i = 0; i < argc; ++i) {
service->argv[i] = strdup(argv[i]);
if (!service->argv[i])
return error_origin(-ENOMEM);
Expand Down

0 comments on commit 6d9b817

Please sign in to comment.