ret = cmd->handler(fd, argc, argv);
mutex_lock(mmd_mutex);
mmd->num_commands++;
- free(mmd->afd.afhi.info_string);
- free(mmd->afd.afhi.chunk_table);
mutex_unlock(mmd_mutex);
if (ret >= 0)
goto out;
int new_fd, ret, i;
char *peer_name;
pid_t child_pid;
+ uint32_t *chunk_table;
+ char *info_string;
if (!FD_ISSET(sct->listen_fd, &s->rfds))
return;
mmd->num_connects++;
mmd->active_connections++;
random();
+ /* The chunk table and the info_string are pointers located in the
+ * mmd struct that point to dynamically allocated memory that must be
+ * freed by the parent and the child. However, as the mmd struct is in
+ * a shared memory area, there's no guarantee that after the fork these
+ * pointers are still valid in child context. As these two pointers are
+ * not used in the child anyway, we save them to local variables and
+ * free the memory via that copy in the child.
+ */
+ info_string = mmd->afd.afhi.info_string;
+ chunk_table = mmd->afd.afhi.chunk_table;
child_pid = fork();
if (child_pid < 0) {
ret = -ERRNO_TO_PARA_ERROR(errno);
/* parent keeps accepting connections */
return;
}
+ /* mmd might already have changed at this point */
+ free(info_string);
+ free(chunk_table);
alarm(ALARM_TIMEOUT);
close_listed_fds();
para_signal_shutdown();