mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-28 18:49:34 -05:00
Fixed some memory allocation/freeing bugs
This commit is contained in:
parent
0ebba25d99
commit
8d57c9fe45
21 changed files with 105 additions and 86 deletions
|
|
@ -50,8 +50,8 @@ LDAPMessageQueue* LDAPAddRequest::sendRequest(){
|
|||
LDAPControl** tmpClCtrls = m_cons->getClCtrlsArray();
|
||||
int err=ldap_add_ext(m_connection->getSessionHandle(),
|
||||
m_entry->getDN().c_str(),attrs,tmpSrvCtrls,tmpClCtrls,&msgID);
|
||||
ldap_controls_free(tmpSrvCtrls);
|
||||
ldap_controls_free(tmpClCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
|
||||
ldap_mods_free(attrs,1);
|
||||
if(err != LDAP_SUCCESS){
|
||||
throw LDAPException(err);
|
||||
|
|
|
|||
|
|
@ -211,8 +211,8 @@ void LDAPAsynConnection::unbind(){
|
|||
LDAPControl** tmpClCtrls=m_constr->getClCtrlsArray();
|
||||
int err=ldap_unbind_ext(cur_session, tmpSrvCtrls, tmpClCtrls);
|
||||
cur_session=0;
|
||||
ldap_controls_free(tmpSrvCtrls);
|
||||
ldap_controls_free(tmpClCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
|
||||
if(err != LDAP_SUCCESS){
|
||||
throw LDAPException(err);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,18 +123,18 @@ const StringList& LDAPAttribute::getValues() const{
|
|||
|
||||
BerValue** LDAPAttribute::getBerValues() const{
|
||||
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getBerValues()" << endl);
|
||||
size_t size=m_values.size();
|
||||
size_t size=m_values.size();
|
||||
if (size == 0){
|
||||
return 0;
|
||||
}else{
|
||||
BerValue **temp = new BerValue*[size+1];
|
||||
BerValue **temp = (BerValue**) malloc(sizeof(BerValue*) * (size+1));
|
||||
StringList::const_iterator i;
|
||||
int p=0;
|
||||
|
||||
for(i=m_values.begin(), p=0; i!=m_values.end(); i++,p++){
|
||||
temp[p]=new BerValue;
|
||||
temp[p]=(BerValue*) malloc(sizeof(BerValue));
|
||||
temp[p]->bv_len= i->size();
|
||||
temp[p]->bv_val= new char[i->size()+1];
|
||||
temp[p]->bv_val= (char*) malloc(sizeof(char) * (i->size()+1));
|
||||
i->copy(temp[p]->bv_val,string::npos);
|
||||
}
|
||||
temp[size]=0;
|
||||
|
|
@ -162,37 +162,37 @@ void LDAPAttribute::setName(const string& name){
|
|||
// The bin-FLAG of the mod_op is always set to LDAP_MOD_BVALUES (0x80)
|
||||
LDAPMod* LDAPAttribute::toLDAPMod() const {
|
||||
DEBUG(LDAP_DEBUG_TRACE, "LDAPAttribute::toLDAPMod()" << endl);
|
||||
LDAPMod* ret=new LDAPMod();
|
||||
ret->mod_op=LDAP_MOD_BVALUES; //always assume binary-Values
|
||||
ret->mod_type= new char[m_name.size()+1];
|
||||
LDAPMod* ret= (LDAPMod*) malloc(sizeof(LDAPMod));
|
||||
ret->mod_op=LDAP_MOD_BVALUES; //always assume binary-Values
|
||||
ret->mod_type= (char*) malloc(sizeof(char) * (m_name.size()+1));
|
||||
m_name.copy(ret->mod_type,string::npos);
|
||||
ret->mod_type[m_name.size()]=0;
|
||||
ret->mod_bvalues=this->getBerValues();
|
||||
return ret;
|
||||
ret->mod_bvalues=this->getBerValues();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool LDAPAttribute::isNotPrintable() const {
|
||||
StringList::const_iterator i;
|
||||
for(i=m_values.begin(); i!=m_values.end(); i++){
|
||||
size_t len = i->size();
|
||||
for(size_t j=0; j<len; j++){
|
||||
if (! isprint( (i->data())[j] ) ){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
StringList::const_iterator i;
|
||||
for(i=m_values.begin(); i!=m_values.end(); i++){
|
||||
size_t len = i->size();
|
||||
for(size_t j=0; j<len; j++){
|
||||
if (! isprint( (i->data())[j] ) ){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ostream& operator << (ostream& s, const LDAPAttribute& attr){
|
||||
s << attr.m_name << "=";
|
||||
StringList::const_iterator i;
|
||||
if (attr.isNotPrintable()){
|
||||
s << "NOT_PRINTABLE" ;
|
||||
}else{
|
||||
for(i=attr.m_values.begin(); i!=attr.m_values.end(); i++){
|
||||
s << *i << " ";
|
||||
}
|
||||
s << attr.m_name << "=";
|
||||
StringList::const_iterator i;
|
||||
if (attr.isNotPrintable()){
|
||||
s << "NOT_PRINTABLE" ;
|
||||
}else{
|
||||
for(i=attr.m_values.begin(); i!=attr.m_values.end(); i++){
|
||||
s << *i << " ";
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ void LDAPAttributeList::addAttribute(const LDAPAttribute& attr){
|
|||
|
||||
LDAPMod** LDAPAttributeList::toLDAPModArray() const{
|
||||
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::toLDAPModArray()" << endl);
|
||||
LDAPMod **ret = new LDAPMod*[m_attrs.size()+1];
|
||||
LDAPMod **ret = (LDAPMod**) malloc((m_attrs.size()+1) * sizeof(LDAPMod*));
|
||||
AttrList::const_iterator i;
|
||||
int j=0;
|
||||
for (i=m_attrs.begin(); i!= m_attrs.end(); i++, j++){
|
||||
|
|
|
|||
|
|
@ -42,12 +42,12 @@ LDAPMessageQueue* LDAPBindRequest::sendRequest(){
|
|||
const char* mech = (m_mech == "" ? 0 : m_mech.c_str());
|
||||
BerValue* tmpcred=0;
|
||||
if(m_cred != ""){
|
||||
char* tmppwd = new char[m_cred.size()+1];
|
||||
char* tmppwd = (char*) malloc( (m_cred.size()+1) * sizeof(char));
|
||||
m_cred.copy(tmppwd,string::npos);
|
||||
tmppwd[m_cred.size()]=0;
|
||||
tmpcred=ber_bvstr(tmppwd);
|
||||
}else{
|
||||
tmpcred=new BerValue;
|
||||
tmpcred=(BerValue*) malloc(sizeof(BerValue));
|
||||
tmpcred->bv_len=0;
|
||||
tmpcred->bv_val=0;
|
||||
}
|
||||
|
|
@ -59,8 +59,8 @@ LDAPMessageQueue* LDAPBindRequest::sendRequest(){
|
|||
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
|
||||
int err=ldap_sasl_bind(m_connection->getSessionHandle(),dn,
|
||||
mech, tmpcred, tmpSrvCtrls, tmpClCtrls, &msgID);
|
||||
ldap_controls_free(tmpSrvCtrls);
|
||||
ldap_controls_free(tmpClCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
|
||||
ber_bvfree(tmpcred);
|
||||
|
||||
if(err != LDAP_SUCCESS){
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ LDAPMessageQueue* LDAPCompareRequest::sendRequest(){
|
|||
m_attr.getName().c_str(), val[0], tmpSrvCtrls,
|
||||
tmpClCtrls, &msgID);
|
||||
ber_bvecfree(val);
|
||||
ldap_controls_free(tmpSrvCtrls);
|
||||
ldap_controls_free(tmpClCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
|
||||
if(err != LDAP_SUCCESS){
|
||||
throw LDAPException(err);
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -79,3 +79,10 @@ LDAPControl* LDAPCtrl::getControlStruct() const {
|
|||
return ret;
|
||||
}
|
||||
|
||||
void LDAPCtrl::freeLDAPControlStruct(LDAPControl *ctrl){
|
||||
DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::freeControlStruct()" << endl);
|
||||
delete[] ctrl->ldctl_oid;
|
||||
delete[] ctrl->ldctl_value.bv_val;
|
||||
delete ctrl;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@ class LDAPCtrl{
|
|||
* the C-API
|
||||
*/
|
||||
LDAPControl* getControlStruct() const;
|
||||
|
||||
static void freeLDAPControlStruct(LDAPControl *ctrl);
|
||||
|
||||
private :
|
||||
std::string m_oid;
|
||||
std::string m_data;
|
||||
|
|
|
|||
|
|
@ -72,3 +72,12 @@ LDAPControl** LDAPControlSet::toLDAPControlArray() const{
|
|||
}
|
||||
}
|
||||
|
||||
void LDAPControlSet::freeLDAPControlArray(LDAPControl **ctrl){
|
||||
DEBUG(LDAP_DEBUG_TRACE, "LDAPControlSet::freeLDAPControlArray()" << endl);
|
||||
if( ctrl ){
|
||||
for( LDAPControl **i = ctrl; *i != 0; ++i ){
|
||||
LDAPCtrl::freeLDAPControlStruct(*i);
|
||||
}
|
||||
}
|
||||
delete[] ctrl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class LDAPControlSet {
|
|||
* LDAPControl-structures as needed by the C-API
|
||||
*/
|
||||
LDAPControl** toLDAPControlArray()const ;
|
||||
|
||||
static void freeLDAPControlArray(LDAPControl **ctrl);
|
||||
private :
|
||||
CtrlList data;
|
||||
} ;
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ LDAPMessageQueue* LDAPDeleteRequest::sendRequest(){
|
|||
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
|
||||
int err=ldap_delete_ext(m_connection->getSessionHandle(),m_dn.c_str(),
|
||||
tmpSrvCtrls, tmpClCtrls ,&msgID);
|
||||
ldap_controls_free(tmpSrvCtrls);
|
||||
ldap_controls_free(tmpClCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
|
||||
if(err != LDAP_SUCCESS){
|
||||
throw LDAPException(err);
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ LDAPEntry::LDAPEntry(const LDAPAsynConnection *ld, LDAPMessage *msg){
|
|||
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry()" << endl);
|
||||
char* tmp=ldap_get_dn(ld->getSessionHandle(),msg);
|
||||
m_dn=string(tmp);
|
||||
delete[] tmp;
|
||||
free(tmp);
|
||||
m_attrs = new LDAPAttributeList(ld, msg);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,17 +41,17 @@ LDAPMessageQueue* LDAPExtRequest::sendRequest(){
|
|||
int msgID=0;
|
||||
BerValue* tmpdata=0;
|
||||
if(m_data != ""){
|
||||
tmpdata=new BerValue;
|
||||
tmpdata=(BerValue*) malloc(sizeof(BerValue));
|
||||
tmpdata->bv_len = m_data.size();
|
||||
tmpdata->bv_val = new char[m_data.size()];
|
||||
tmpdata->bv_val = (char*) malloc(sizeof(char) * (m_data.size()) );
|
||||
m_data.copy(tmpdata->bv_val, string::npos);
|
||||
}
|
||||
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
|
||||
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
|
||||
int err=ldap_extended_operation(m_connection->getSessionHandle(),
|
||||
m_oid.c_str(), tmpdata, tmpSrvCtrls, tmpClCtrls, &msgID);
|
||||
ldap_controls_free(tmpSrvCtrls);
|
||||
ldap_controls_free(tmpClCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
|
||||
ber_bvfree(tmpdata);
|
||||
if(err != LDAP_SUCCESS){
|
||||
delete this;
|
||||
|
|
|
|||
|
|
@ -41,18 +41,18 @@ LDAPMessageQueue::~LDAPMessageQueue(){
|
|||
|
||||
LDAPMsg *LDAPMessageQueue::getNext(){
|
||||
DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getNext()" << endl);
|
||||
LDAPMessage *msg;
|
||||
LDAPMessage *msg;
|
||||
LDAPRequest *req=m_activeReq.top();
|
||||
int msg_id = req->getMsgID();
|
||||
int res;
|
||||
int res;
|
||||
const LDAPAsynConnection *con=req->getConnection();
|
||||
res=ldap_result(con->getSessionHandle(),msg_id,0,0,&msg);
|
||||
if (res <= 0){
|
||||
if(msg != 0){
|
||||
ldap_msgfree(msg);
|
||||
}
|
||||
throw LDAPException(con);
|
||||
}else{
|
||||
throw LDAPException(con);
|
||||
}else{
|
||||
const LDAPConstraints *constr=req->getConstraints();
|
||||
LDAPMsg *ret=0;
|
||||
//this can throw an exception (Decoding Error)
|
||||
|
|
@ -144,7 +144,7 @@ LDAPMsg *LDAPMessageQueue::getNext(){
|
|||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Maybe moved to LDAPRequest::followReferral seems more reasonable
|
||||
|
|
|
|||
|
|
@ -60,8 +60,8 @@ LDAPMessageQueue* LDAPModDNRequest::sendRequest(){
|
|||
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
|
||||
int err=ldap_rename(m_connection->getSessionHandle(),m_dn.c_str(),newRDN,
|
||||
newParentDN,m_deleteOld ? 1 : 0, tmpSrvCtrls, tmpClCtrls,&msg_id);
|
||||
ldap_controls_free(tmpSrvCtrls);
|
||||
ldap_controls_free(tmpClCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
|
||||
if(err!=LDAP_SUCCESS){
|
||||
throw LDAPException(err);
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -25,12 +25,13 @@ void LDAPModList::addModification(const LDAPModification &mod){
|
|||
|
||||
LDAPMod** LDAPModList::toLDAPModArray(){
|
||||
DEBUG(LDAP_DEBUG_TRACE,"LDAPModList::toLDAPModArray()" << endl);
|
||||
LDAPMod **ret = new LDAPMod*[m_modList.size()+1];
|
||||
ret[m_modList.size()]=0;
|
||||
ModList::const_iterator i;
|
||||
int j=0;
|
||||
for (i=m_modList.begin(); i != m_modList.end(); i++ , j++){
|
||||
ret[j]=i->toLDAPMod();
|
||||
}
|
||||
return ret;
|
||||
LDAPMod **ret = (LDAPMod**) malloc(
|
||||
(m_modList.size()+1) * sizeof(LDAPMod*));
|
||||
ret[m_modList.size()]=0;
|
||||
ModList::const_iterator i;
|
||||
int j=0;
|
||||
for (i=m_modList.begin(); i != m_modList.end(); i++ , j++){
|
||||
ret[j]=i->toLDAPMod();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,27 +13,27 @@ LDAPModification::LDAPModification(const LDAPAttribute& attr, mod_op op){
|
|||
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPModification::LDAPModification()" << endl);
|
||||
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
|
||||
" attr:" << attr << endl);
|
||||
m_attr = attr;
|
||||
m_mod_op = op;
|
||||
m_attr = attr;
|
||||
m_mod_op = op;
|
||||
}
|
||||
|
||||
LDAPMod* LDAPModification::toLDAPMod() const {
|
||||
DEBUG(LDAP_DEBUG_TRACE,"LDAPModification::toLDAPMod()" << endl);
|
||||
LDAPMod* ret=m_attr.toLDAPMod();
|
||||
LDAPMod* ret=m_attr.toLDAPMod();
|
||||
|
||||
//The mod_op value of the LDAPMod-struct needs to be ORed with the right
|
||||
// LDAP_MOD_* constant to preserve the BIN-flag (see CAPI-draft for
|
||||
//The mod_op value of the LDAPMod-struct needs to be ORed with the right
|
||||
// LDAP_MOD_* constant to preserve the BIN-flag (see CAPI-draft for
|
||||
// explanation of the LDAPMod struct)
|
||||
switch (m_mod_op){
|
||||
case OP_ADD :
|
||||
ret->mod_op |= LDAP_MOD_ADD;
|
||||
break;
|
||||
case OP_DELETE :
|
||||
ret->mod_op |= LDAP_MOD_DELETE;
|
||||
break;
|
||||
case OP_REPLACE :
|
||||
ret->mod_op |= LDAP_MOD_REPLACE;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
switch (m_mod_op){
|
||||
case OP_ADD :
|
||||
ret->mod_op |= LDAP_MOD_ADD;
|
||||
break;
|
||||
case OP_DELETE :
|
||||
ret->mod_op |= LDAP_MOD_DELETE;
|
||||
break;
|
||||
case OP_REPLACE :
|
||||
ret->mod_op |= LDAP_MOD_REPLACE;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,8 +51,9 @@ LDAPMessageQueue* LDAPModifyRequest::sendRequest(){
|
|||
LDAPMod** tmpMods=m_modList->toLDAPModArray();
|
||||
int err=ldap_modify_ext(m_connection->getSessionHandle(),m_dn.c_str(),
|
||||
tmpMods, tmpSrvCtrls, tmpClCtrls,&msgID);
|
||||
ldap_controls_free(tmpSrvCtrls);
|
||||
ldap_controls_free(tmpClCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
|
||||
ldap_mods_free(tmpMods,1);
|
||||
if(err != LDAP_SUCCESS){
|
||||
throw LDAPException(err);
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ LDAPResult::LDAPResult(const LDAPRequest *req, LDAPMessage *msg) :
|
|||
}
|
||||
if(matchedDN != 0){
|
||||
m_matchedDN=string(matchedDN);
|
||||
delete[] matchedDN;
|
||||
free(matchedDN);
|
||||
}
|
||||
if(errMsg != 0){
|
||||
m_errMsg=string(errMsg);
|
||||
delete[] errMsg;
|
||||
free(errMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,8 +71,8 @@ LDAPMessageQueue* LDAPSearchRequest::sendRequest(){
|
|||
tmpClCtrl, tmptime, m_cons->getSizeLimit(), &msgID );
|
||||
delete tmptime;
|
||||
ldap_value_free(tmpattrs);
|
||||
ldap_controls_free(tmpSrvCtrl);
|
||||
ldap_controls_free(tmpClCtrl);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrl);
|
||||
LDAPControlSet::freeLDAPControlArray(tmpClCtrl);
|
||||
|
||||
if (err != LDAP_SUCCESS){
|
||||
throw LDAPException(err);
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ StringList::~StringList(){
|
|||
|
||||
char** StringList::toCharArray() const{
|
||||
if(!empty()){
|
||||
char** ret = new char*[size()+1];
|
||||
char** ret = (char**) malloc(sizeof(char*) * (size()+1));
|
||||
StringList::const_iterator i;
|
||||
int j=0;
|
||||
for(i=begin(); i != end(); i++,j++){
|
||||
ret[j]=new char[i->size()+1];
|
||||
ret[j]=(char*) malloc(sizeof(char) * (i->size()+1));
|
||||
i->copy(ret[j],string::npos);
|
||||
ret[j][i->size()]=0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue