Ignore:
Timestamp:
Jun 27, 2014, 1:14:39 AM (10 years ago)
Author:
djay
Message:

Remove memory leaks from ZOO-Kernel. Fix issue #99.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/zoo_loader.c

    r465 r490  
    5454
    5555xmlXPathObjectPtr extractFromDoc(xmlDocPtr,const char*);
    56 int runRequest(map*);
     56int runRequest(map**);
    5757
    5858using namespace std;
     
    9191  if(strncmp(cgiContentType,"text/xml",8)==0 ||
    9292     strncasecmp(cgiRequestMethod,"post",4)==0){
    93     if(cgiContentLength==NULL){
    94        cgiContentLength=0;
     93    if(cgiContentLength==0){
    9594       char *buffer=new char[2];
    9695       char *res=NULL;
    9796       int r=0;
    9897       while((r=fread(buffer,sizeof(char),1,cgiIn))){
     98         buffer[1]=0;
    9999         cgiContentLength+=r;
    100100         if(res==NULL){
    101            res=(char*)malloc(1*sizeof(char));
     101           res=(char*)malloc(2*sizeof(char));
    102102           sprintf(res,"%s",buffer);
    103103         }
    104104         else{
    105            res=(char*)realloc(res,(cgiContentLength+1)*sizeof(char));
    106105           char *tmp=zStrdup(res);
     106           res=(char*)realloc(res,(strlen(tmp)+2)*sizeof(char));
    107107           sprintf(res,"%s%s",tmp,buffer);
    108108           free(tmp);
    109109         }
    110110       }
     111       delete[] buffer;
    111112       if(res==NULL && (strQuery==NULL || strlen(strQuery)==0)){
    112113         return errorException(NULL,"ZOO-Kernel failed to process your request cause the request was emtpty.","InternalError",NULL);
     
    114115         if(strQuery==NULL || strlen(strQuery)==0)
    115116           tmpMap=createMap("request",res);
    116             }
     117       }
     118       if(res!=NULL)
     119         free(res);
    117120    }else{
    118121      char *buffer=new char[cgiContentLength+1];
    119       if(fread(buffer,sizeof(char),cgiContentLength,cgiIn)>=0){
     122      if(fread(buffer,sizeof(char),cgiContentLength,cgiIn)>0){
    120123        buffer[cgiContentLength]=0;
    121124        tmpMap=createMap("request",buffer);
     
    146149          arrayStep++;
    147150        }
    148         tmpMap=createMap("request",buffer);
     151        if(tmpMap!=NULL)
     152          addToMap(tmpMap,"request",buffer);
     153        else
     154          tmpMap=createMap("request",buffer);
    149155      }
    150156      delete[]buffer;
     
    202208#endif
    203209     ){
    204     /**
    205      * First include the MetaPath and the ServiceProvider default parameters
    206      * (which should be always available in GET params so in cgiQueryString)
    207      */
    208     char *str1;
    209     str1=cgiQueryString;
    210210    /**
    211211     * Store the original XML request in xrequest map
     
    232232            }
    233233          }
     234          xmlXPathFreeObject(reqptr);
    234235        }
    235236      }
     
    239240      tval=NULL;
    240241      tval = (char*) xmlGetProp(cur,BAD_CAST "service");
    241       if(tval!=NULL)
     242      if(tval!=NULL){
    242243        addToMap(tmpMap,"service",tval);
     244        xmlFree(tval);
     245      }
    243246      tval=NULL;
    244247      tval = (char*) xmlGetProp(cur,BAD_CAST "language");
    245       if(tval!=NULL)
     248      if(tval!=NULL){
    246249        addToMap(tmpMap,"language",tval);
     250        xmlFree(tval);
     251      }
    247252      const char* requests[3]={"GetCapabilities","DescribeProcess","Execute"};
    248253      for(int j=0;j<3;j++){
     
    256261#endif
    257262          if(req!=NULL && req->nodeNr==1){
     263            if(t1->value!=NULL)
     264              free(t1->value);
    258265            t1->value=zStrdup(requests[j]);
    259266            j=2;
     
    272279        tval=NULL;
    273280        tval = (char*) xmlGetProp(cur,BAD_CAST "version");
    274         if(tval!=NULL)
     281        if(tval!=NULL){
    275282          addToMap(tmpMap,"version",tval);
     283          xmlFree(tval);
     284        }
    276285        tval = (char*) xmlGetProp(cur,BAD_CAST "language");
    277         if(tval!=NULL)
     286        if(tval!=NULL){
    278287          addToMap(tmpMap,"language",tval);
     288          xmlFree(tval);
     289        }
    279290        xmlXPathObjectPtr idptr=extractFromDoc(doc,"/*/*[local-name()='Identifier']");
    280291        if(idptr!=NULL){
     
    343354  if(strQuery!=NULL)
    344355    free(strQuery);
    345   runRequest(tmpMap);
     356
     357  runRequest(&tmpMap);
    346358
    347359  /**
    348360   * Required but can't be made after executing a process using POST requests.
    349361   */
    350   if(strncasecmp(cgiRequestMethod,"post",4)!=0 && count(tmpMap)!=1 && tmpMap!=NULL){
     362  if(/*strncasecmp(cgiRequestMethod,"post",4)!=0 && count(tmpMap)!=1 && */tmpMap!=NULL){
    351363    freeMap(&tmpMap);
    352364    free(tmpMap);
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png