You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "guoxiang niu (JIRA)" <ji...@apache.org> on 2017/08/23 15:18:00 UTC

[jira] [Comment Edited] (ZOOKEEPER-2881) memory leak in create_buffer_iarchive() and create_buffer_oarchive()

    [ https://issues.apache.org/jira/browse/ZOOKEEPER-2881?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16138467#comment-16138467 ] 

guoxiang niu edited comment on ZOOKEEPER-2881 at 8/23/17 3:17 PM:
------------------------------------------------------------------

1、
struct iarchive *create_buffer_iarchive(char *buffer, int len)
{
    struct iarchive *ia = NULL;
    struct buff_struct *buff = NULL;
    ia = malloc(sizeof(*ia));
    if (!ia) return 0;
    buff = malloc(sizeof(struct buff_struct));
    if (!buff) {
        free(ia);
        return 0;
    }
......
2、
struct oarchive *create_buffer_oarchive()
{
    struct oarchive *oa = NULL;
    struct buff_struct *buff = NULL;
    oa = malloc(sizeof(*oa));
    if (!oa) return 0;
    buff = malloc(sizeof(struct buff_struct));
    if (!buff) {
        free(oa);
        return 0;
    }
......


was (Author: guoxiang):
struct iarchive *create_buffer_iarchive(char *buffer, int len)
{
    struct iarchive *ia = NULL;
    struct buff_struct *buff = NULL;
    ia = malloc(sizeof(*ia));
    if (!ia) return 0;
    buff = malloc(sizeof(struct buff_struct));
    if (!buff) {
        free(ia);
        return 0;
    }
......
struct oarchive *create_buffer_oarchive()
{
    struct oarchive *oa = NULL;
    struct buff_struct *buff = NULL;
    oa = malloc(sizeof(*oa));
    if (!oa) return 0;
    buff = malloc(sizeof(struct buff_struct));
    if (!buff) {
        free(oa);
        return 0;
    }
......

> memory leak in create_buffer_iarchive() and create_buffer_oarchive()
> --------------------------------------------------------------------
>
>                 Key: ZOOKEEPER-2881
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2881
>             Project: ZooKeeper
>          Issue Type: Bug
>          Components: c client
>            Reporter: guoxiang niu
>            Priority: Minor
>
> in create_buffer_iarchive() function, null check of ia and return should be done before allocing memory for buff, otherwise, memory of buff might be leak.
> same issue is existing in create_buffer_oarchive() function.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)