Fix memory leak in CUPS IPP processing

This resolves Bug 1369
pull/16/head
Roman Savochenko 13 years ago committed by Slávek Banko
parent 1ae857eec3
commit 5f99a27180

@ -21,6 +21,7 @@
#include "cupsinfos.h" #include "cupsinfos.h"
#include <stdlib.h> #include <stdlib.h>
#include <string>
#include <cups/language.h> #include <cups/language.h>
#include <kdebug.h> #include <kdebug.h>
#include <kglobal.h> #include <kglobal.h>
@ -227,14 +228,19 @@ void IppRequest::addStringList_p(int group, int type, const TQString& name, cons
{ {
if (!name.isEmpty()) if (!name.isEmpty())
{ {
ipp_attribute_t *attr = ippAddStrings(request_,(ipp_tag_t)group,(ipp_tag_t)type,name.latin1(),(int)(values.count()),NULL,NULL); //> Values buffer and references offset prepare
int i(0); const char *vlsRefs[values.count()];
for (TQStringList::ConstIterator it=values.begin(); it != values.end(); ++it, i++) std::string vlsBuf;
#ifdef HAVE_CUPS_1_6 for(unsigned i_vl = 0; i_vl < values.count(); i_vl++)
ippSetString(request_, &attr, i, strdup((*it).local8Bit())); {
#else // HAVE_CUPS_1_6 vlsRefs[i_vl] = (const char*)vlsBuf.size();
attr->values[i].string.text = strdup((*it).local8Bit()); vlsBuf += values[i_vl].local8Bit();
#endif // HAVE_CUPS_1_6 vlsBuf += (char)0;
}
//> References update to pointers
for(unsigned i_vl = 0; i_vl < values.count(); i_vl++)
vlsRefs[i_vl] = vlsBuf.data()+(intptr_t)vlsRefs[i_vl];
ippAddStrings(request_,(ipp_tag_t)group,(ipp_tag_t)type,name.latin1(),(int)(values.count()),NULL,(const char**)&vlsRefs);
} }
} }

Loading…
Cancel
Save