[CDRIVER-3515] _mongoc_get_rr_search calls free instead of bson_free on bson_malloc'ed object Created: 02/Feb/20  Updated: 28/Oct/23  Resolved: 03/Feb/20

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.16.0
Fix Version/s: 1.16.1

Type: Bug Priority: Trivial - P5
Reporter: Kevin Albertson Assignee: Kevin Albertson
Resolution: Fixed Votes: 0
Labels: codeql
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CDRIVER-3388 SRV record lookup fails if DNS respon... Closed

 Description   

Found with this CodeQL query (which checks for function returns where variables that are assigned a result of a bson_malloc* have no associated bson_free statement):

import cpp
 
from FunctionCall alloc, LocalScopeVariable v, ReturnStmt return
where
(
    alloc.getTarget().getQualifiedName() = "bson_malloc" or
    alloc.getTarget().getQualifiedName() = "bson_malloc0" or
    alloc.getTarget().getQualifiedName() = "bson_realloc" or
    alloc.getTarget().getQualifiedName() = "bson_calloc"
) and
v.getAnAssignedValue() = alloc and
alloc.getASuccessor+() = return and
not alloc.getEnclosingFunction().getQualifiedName().matches("%new%") and
not alloc.getEnclosingFunction().getQualifiedName().matches("%dup%") and
not alloc.getEnclosingFunction().getQualifiedName().matches("%clone%") and
not alloc.getEnclosingFunction().getQualifiedName().matches("%init%") and
not return.getExpr() = v.getAnAccess() and
not exists (FunctionCall free |
    free.getTarget().getQualifiedName() = "bson_free" and
    free.getAnArgument() = v.getAnAccess() and
    free.getASuccessor+() = return and 
    free.getAPredecessor+() = alloc
)
 
select return, "leaks", v, "in ", alloc.getEnclosingFunction().getQualifiedName()



 Comments   
Comment by Githook User [ 04/Feb/20 ]

Author:

{'username': 'kevinAlbs', 'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com'}

Message: CDRIVER-3515 call bson_free instead of free
Branch: r1.16
https://github.com/mongodb/mongo-c-driver/commit/5ce63871ca4fc32295951b3b3e3ce6c23d5f6e8d

Comment by Githook User [ 03/Feb/20 ]

Author:

{'username': 'kevinAlbs', 'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com'}

Message: CDRIVER-3515 call bson_free instead of free
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/b12e2a44dd2a3321aecd0222dcde173b8c5b9457

Generated at Wed Feb 07 21:18:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.