libsmtp--库的一个bug

http://libsmtp.sourceforge.net/

 

用纯C写的smtp客户端已经很少了,更重要的是性能要好,不要有太多附加的东西,只需要完成smtp主要协议就行,

我还是很喜欢这个项目的,我用它做smtp邮件系统的性能测试,可惜好久没更新了。

 

file:plg_login.c

 

    /* username */
    usr = (char*)malloc_ (2*strlen (srv->username)+4);
    siz = alg_b64_encode (srv->username, strlen (srv->username), usr);

    if (smtp_write (srv, usr, siz) == -1)
    {
        free_ (usr, NULL);
        return (-1); /* error msg is already set */
    }
   
    if ((rsp = smtp_read_response_ (srv, 1)) == NULL)
    {
        free_ (usr, NULL);
        return (-1); /* error msg is already set */
    }
    free_ (rsp, usr, NULL);

    /* password */
    pwd = (char*)malloc_ (2*strlen (srv->password)+4);
    siz = alg_b64_encode (srv->password, strlen (srv->password), pwd);

    if (smtp_write (srv, pwd, siz) == -1)
    {
        free_ (pwd, NULL);
        return (-1); /* error msg is already set */
    }
   
    if ((rsp = smtp_read_response_ (srv, 1)) == NULL)
    {
        free_ (pwd, NULL);
        return (-1); /* error msg is already set */
    }
//    free_ (rsp, usr, NULL);
/*
change usr to pwd.
*/
      free_ (rsp, pwd, NULL);

 

释放指针的时候对usr释放了两次,导致系统报错double free。

第二次usr释放应该改为释放pwd。

 

你可能感兴趣的:(C++,c,.net,C#)