Commit 9360a73c authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

crtools: Make close_cr_fdset being safe to be called with closed fd-set

It was being done intentionally to be able to call close_cr_fdset
several times in a row, bring this ability back. Otherwise I'm
getting glibc complains about attemt to free already freed memory.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent e4d21f5a
......@@ -1233,11 +1233,11 @@ int cr_dump_tasks(pid_t pid, struct cr_options *opts)
if (dump_task_thread(item->threads[i], cr_fdset_thread))
goto err;
close_cr_fdset(cr_fdset_thread);
close_cr_fdset(&cr_fdset_thread);
}
}
close_cr_fdset(cr_fdset);
close_cr_fdset(&cr_fdset);
if (opts->leader_only)
break;
......@@ -1256,8 +1256,8 @@ err:
free_pstree(&pstree_list);
close_cr_fdset(cr_fdset);
close_cr_fdset(cr_fdset_thread);
close_cr_fdset(&cr_fdset);
close_cr_fdset(&cr_fdset_thread);
return ret;
}
......@@ -512,7 +512,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
lseek(cr_fdset->fds[CR_FD_PSTREE], MAGIC_OFFSET, SEEK_SET);
show_pstree(cr_fdset->fds[CR_FD_PSTREE]);
close_cr_fdset(cr_fdset);
close_cr_fdset(&cr_fdset);
list_for_each_entry(item, &pstree_list, list) {
......@@ -545,7 +545,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
pr_info("----------------------------------------\n");
close_cr_fdset(cr_fdset_th);
close_cr_fdset(&cr_fdset_th);
}
}
......@@ -559,7 +559,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
show_unixsk(cr_fdset->fds[CR_FD_UNIXSK]);
close_cr_fdset(cr_fdset);
close_cr_fdset(&cr_fdset);
if (opts->leader_only)
break;
......@@ -567,7 +567,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
out:
free_pstree(&pstree_list);
close_cr_fdset(cr_fdset);
close_cr_fdset(&cr_fdset);
return ret;
}
......
......@@ -180,23 +180,27 @@ err:
return cr_fdset;
}
void close_cr_fdset(struct cr_fdset *cr_fdset)
void close_cr_fdset(struct cr_fdset **cr_fdset)
{
struct cr_fdset *fdset;
unsigned int i;
if (!cr_fdset)
if (!cr_fdset || !*cr_fdset)
return;
fdset = *cr_fdset;
for (i = 0; i < CR_FD_MAX; i++) {
if (cr_fdset->fds[i] == -1)
if (fdset->fds[i] == -1)
continue;
pr_debug("Closed %d/%d\n", i, cr_fdset->fds[i]);
close(cr_fdset->fds[i]);
cr_fdset->fds[i] = -1;
pr_debug("Closed %d/%d\n", i, fdset->fds[i]);
close(fdset->fds[i]);
fdset->fds[i] = -1;
}
free(cr_fdset);
xfree(fdset);
*cr_fdset = NULL;
}
int get_image_path(char *path, int size, const char *fmt, int pid)
......
......@@ -87,7 +87,7 @@ int convert_to_elf(char *elf_path, int fd_core);
struct cr_fdset *prep_cr_fdset_for_dump(int pid, unsigned long use_mask);
struct cr_fdset *prep_cr_fdset_for_restore(int pid, unsigned long use_mask);
void close_cr_fdset(struct cr_fdset *cr_fdset);
void close_cr_fdset(struct cr_fdset **cr_fdset);
void free_mappings(struct list_head *vma_area_list);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment