Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leaks #721

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions src/librc/librc-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,31 @@ rc_proc_getent(const char *ent RC_UNUSED)
{
#ifdef __linux__
FILE *fp;
char *proc, *p, *value = NULL;
char *proc = NULL, *p, *value = NULL, *save;
size_t i, len;
ssize_t size;

if (!exists("/proc/cmdline"))
return NULL;

if (!(fp = fopen("/proc/cmdline", "r")))
return NULL;

proc = NULL;
i = 0;
if (rc_getline(&proc, &i, fp) == -1 || proc == NULL)
if ((size = getline(&proc, &i, fp) == -1)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks wrong: the first closing paren is in the wrong place. Should be this:

	if ((size = getline(&proc, &i, fp)) == -1) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #742.

free(proc);
return NULL;

if (proc != NULL) {
len = strlen(ent);

while ((p = strsep(&proc, " "))) {
if (strncmp(ent, p, len) == 0 && (p[len] == '\0' || p[len] == ' ' || p[len] == '=')) {
p += len;

if (*p == '=')
p++;

value = xstrdup(p);
}
}
proc[size - 1] = '\0';
save = proc;

len = strlen(ent);
while ((p = strsep(&save, " "))) {
if (strncmp(ent, p, len) == 0 && (p[len] == '\0' || p[len] == ' ' || p[len] == '=')) {
p += len;
if (*p == '=')
p++;
value = xstrdup(p);
}
}

Expand Down Expand Up @@ -332,35 +331,36 @@ static RC_STRINGLIST * rc_config_directory(RC_STRINGLIST *config)
{
DIR *dp;
struct dirent *d;
RC_STRINGLIST *rc_conf_d_files = rc_stringlist_new();
RC_STRINGLIST *rc_conf_d_files;
RC_STRING *fname;
RC_STRINGLIST *rc_conf_d_list;
char path[PATH_MAX];
RC_STRING *line;

if ((dp = opendir(RC_CONF_D)) != NULL) {
rc_conf_d_files = rc_stringlist_new();
while ((d = readdir(dp)) != NULL) {
if (fnmatch("*.conf", d->d_name, FNM_PATHNAME) == 0) {
rc_stringlist_addu(rc_conf_d_files, d->d_name);
}
}
closedir(dp);

if (rc_conf_d_files) {
rc_stringlist_sort(&rc_conf_d_files);
TAILQ_FOREACH(fname, rc_conf_d_files, entries) {
if (!fname->value)
continue;
sprintf(path, "%s/%s", RC_CONF_D, fname->value);
rc_conf_d_list = rc_config_list(path);
TAILQ_FOREACH(line, rc_conf_d_list, entries)
if (line->value)
rc_config_set_value(config, line->value);
rc_stringlist_free(rc_conf_d_list);
}
rc_stringlist_free(rc_conf_d_files);
rc_stringlist_sort(&rc_conf_d_files);
TAILQ_FOREACH(fname, rc_conf_d_files, entries) {
if (!fname->value)
continue;
sprintf(path, "%s/%s", RC_CONF_D, fname->value);
rc_conf_d_list = rc_config_list(path);
TAILQ_FOREACH(line, rc_conf_d_list, entries)
if (line->value)
rc_config_set_value(config, line->value);
rc_stringlist_free(rc_conf_d_list);
}

rc_stringlist_free(rc_conf_d_files);
}

return config;
}

Expand Down
6 changes: 5 additions & 1 deletion src/openrc/rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,13 @@ do_stop_services(RC_STRINGLIST *types_nw, RC_STRINGLIST *start_services,
pid_t pid;
RC_STRING *service, *svc1, *svc2;
RC_STRINGLIST *deporder, *tmplist, *kwords;
RC_STRINGLIST *types_nw_save = NULL;
RC_SERVICE state;
RC_STRINGLIST *nostop;
bool crashed, nstop;

if (!types_nw) {
types_nw = rc_stringlist_new();
types_nw = types_nw_save = rc_stringlist_new();
rc_stringlist_add(types_nw, "needsme");
rc_stringlist_add(types_nw, "wantsme");
}
Expand Down Expand Up @@ -638,6 +639,9 @@ do_stop_services(RC_STRINGLIST *types_nw, RC_STRINGLIST *start_services,
}
}

if (types_nw_save)
rc_stringlist_free(types_nw_save);

rc_stringlist_free(nostop);
}

Expand Down
2 changes: 2 additions & 0 deletions src/rc-status/rc-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ static char *get_uptime(const char *service)
"%02"PRId64":%02"PRId64":%02"PRId64" (%s)",
diff_hours, diff_mins, diff_secs, start_count);
}
free(start_count);
free(start_time_string);
}
return uptime;
}
Expand Down
Loading