diff --git a/src/systemd-sonic-generator/systemd-sonic-generator.c b/src/systemd-sonic-generator/systemd-sonic-generator.c index 9267a48aa4a6..fb82c41b7af8 100644 --- a/src/systemd-sonic-generator/systemd-sonic-generator.c +++ b/src/systemd-sonic-generator/systemd-sonic-generator.c @@ -592,11 +592,14 @@ int ssg_main(int argc, char **argv) { for (int i = 0; i < num_unit_files; i++) { unit_instance = strdup(unit_files[i]); if ((num_asics == 1) && strstr(unit_instance, "@") != NULL) { - prefix = strtok_r(unit_instance, "@", &saveptr); - suffix = strtok_r(NULL, "@", &saveptr); + prefix = strdup(strtok_r(unit_instance, "@", &saveptr)); + suffix = strdup(strtok_r(NULL, "@", &saveptr)); strcpy(unit_instance, prefix); strcat(unit_instance, suffix); + + free(prefix); + free(suffix); } num_targets = get_install_targets(unit_instance, targets);