[Asterisk-code-review] endpoint snapshot: avoid second cleanup on alloc failure (asterisk[master])

Matt Jordan asteriskteam at digium.com
Sat Sep 5 18:48:17 CDT 2015


Matt Jordan has posted comments on this change.

Change subject: endpoint snapshot: avoid second cleanup on alloc failure
......................................................................


Patch Set 1:

(1 comment)

https://gerrit.asterisk.org/#/c/1183/1/main/endpoints.c
File main/endpoints.c:

Line 484: ao2_cleanup(snapshot);
> I wonder why you didn't just remove this call to ao2_cleanup?
You actually can't here. Consider what happens if:

* snapshot is allocated
* ast_string_field_init fails

In that case, if you don't attempt to clean up the snapshot, this will leak the allocated memory. Since ao2_cleanup is NULL tolerant, it is safe to call if snapshot == NULL.

Granted, it would be a bit clearer to write this as:

snapshot = ao2_alloc_options(...);
if (!snapshot) {
    return NULL;
}

if (ast_string_field_init(snapshot, 80)) {
    ao2_ref(snapshot, -1);
    return NULL;
}


-- 
To view, visit https://gerrit.asterisk.org/1183
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: If4d9dfb1bbe3836b623642ec690b6d49b25e8979
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Scott Griepentrog <sgriepentrog at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Ashley Sanders <asanders at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>
Gerrit-HasComments: Yes



More information about the asterisk-code-review mailing list