c - Valgrind 消息 : invalid file descriptor 1024 in syscall close()

标签 c profiling valgrind

我在用 valgrind 测试我的 bin 时收到这条消息:

==8454== Warning: invalid file descriptor 1024 in syscall close()

我打开一次,关闭一次。下面的函数打开()一个文件,获取内容,然后关闭()文件。

int             parse(t_struct *data)
{
  int           fd;
  char          *s;

  if ((fd = open(data->file, O_RDONLY)) == -1)
    {
      fprintf(stderr, "Cannot open\n");
      return (-1);
    }
  while ((s = gnl(fd)) != NULL)
    {
      if (list_add_elem_at_back(&data->list, s) == FALSE)
        {
          fprintf(stderr,"Cannot stock\n");
          return (-1);
        }
    }
  close(fd);
  return (0);
}

哪里/有什么问题?

最佳答案

使用ulimit -n ,它会显示最大打开文件数,我猜你不会关闭 fd,为了代码的安全。请跟踪每个 fopen 的代码, socketselect必须有 close .

关于c - Valgrind 消息 : invalid file descriptor 1024 in syscall close(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22288766/

相关文章:

c - C 中优先级 and++ 和 * 一元运算符的问题

c - Valgrind 神秘的无效写入大小 8 错误

llvm - 静态和动态仪器的优缺点

c++ - 使用 ffserver 进行 RTMP 流式传输

c - malloc 的每个现代实现都会在程序中引入 UB 吗?

php - MySQL 查询和 PHP 脚本调整 : How can I find the problems?

asp.net - ASP.NET 性能瓶颈之谜

c++ - 需要帮助破译 gprof 输出

c - valgrind : Conditional jump or move depends on uninitialised value using strlen() strncat()

c - sscanf() 跳过分隔符和宽度