免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1994 | 回复: 2
打印 上一主题 下一主题

[C] 发现libevent有个bug [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-07-05 18:58 |只看该作者 |倒序浏览
本帖最后由 liexusong 于 2013-07-05 18:59 编辑

其实不算是bug, 只是觉得有点浪费内存而已, 代码如下:
  1. int
  2. event_base_priority_init(struct event_base *base, int npriorities)
  3. {
  4.         int i;

  5.         if (base->event_count_active)
  6.                 return (-1);

  7.         if (base->nactivequeues && npriorities != base->nactivequeues) {
  8.                 for (i = 0; i < base->nactivequeues; ++i) {
  9.                         free(base->activequeues[i]);
  10.                 }
  11.                 free(base->activequeues);
  12.         }

  13.         /* Allocate our priority queues */
  14.         base->nactivequeues = npriorities;
  15.         base->activequeues = (struct event_list **)calloc(base->nactivequeues,
  16.             npriorities * sizeof(struct event_list *));
  17.         if (base->activequeues == NULL)
  18.                 event_err(1, "%s: calloc", __func__);

  19.         for (i = 0; i < base->nactivequeues; ++i) {
  20.                 base->activequeues[i] = malloc(sizeof(struct event_list));
  21.                 if (base->activequeues[i] == NULL)
  22.                         event_err(1, "%s: malloc", __func__);
  23.                 TAILQ_INIT(base->activequeues[i]);
  24.         }

  25.         return (0);
  26. }
复制代码
在第18行:
base->activequeues = (struct event_list **)calloc(base->nactivequeues,
            npriorities * sizeof(struct event_list *));

我觉得应该改为:
base->activequeues = (struct event_list **)calloc(base->nactivequeues,
            sizeof(struct event_list *));

论坛徽章:
0
2 [报告]
发表于 2013-07-05 19:07 |只看该作者
标题党

论坛徽章:
324
射手座
日期:2013-08-23 12:04:38射手座
日期:2013-08-23 16:18:12未羊
日期:2013-08-30 14:33:15水瓶座
日期:2013-09-02 16:44:31摩羯座
日期:2013-09-25 09:33:52双子座
日期:2013-09-26 12:21:10金牛座
日期:2013-10-14 09:08:49申猴
日期:2013-10-16 13:09:43子鼠
日期:2013-10-17 23:23:19射手座
日期:2013-10-18 13:00:27金牛座
日期:2013-10-18 15:47:57午马
日期:2013-10-18 21:43:38
3 [报告]
发表于 2013-07-05 22:45 |只看该作者
那23、24行的循环对 base->activequeues[i] 赋值不是越界了么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP