Index: trunk/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-kernel/zoo_service_loader.c	(revision 30)
+++ trunk/zoo-kernel/zoo_service_loader.c	(revision 32)
@@ -44,9 +44,5 @@
 #include "service.h"
 #include "service_internal.h"
-
-
-#ifdef USE_PYTHON
 #include "service_internal_python.h"
-#endif
 
 #ifdef USE_JAVA
@@ -182,6 +178,4 @@
     freeMaps(&m);
     free(m);
-    freeMap(&request_inputs);
-    free(request_inputs);
     return 1;
   }
@@ -194,6 +188,4 @@
       freeMaps(&m);
       free(m);
-      freeMap(&request_inputs);
-      free(request_inputs);
       free(REQUEST);
       return 1;
@@ -418,4 +410,8 @@
   s1=(service*)calloc(1,SERVICE_SIZE);
   if(s1 == NULL){
+    freeMaps(&m);
+    free(m);
+    free(REQUEST);
+    free(SERVICE_URL);
     return errorException(m, "Unable to allocate memory.","InternalError");
   }
@@ -437,9 +433,17 @@
   fflush(stdout);
   dup2(saved_stdout,fileno(stdout));
-  if(t==22){
-    errorException(m, "The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request.", "InvalidParameterValue");
-    exit(0);
+  if(t<0){
+    char tmpMsg[2048+strlen(r_inputs->value)];
+    sprintf(tmpMsg,"The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request.",r_inputs->value);
+    errorException(m, tmpMsg, "InvalidParameterValue");
+    freeService(&s1);
+    free(s1);
+    freeMaps(&m);
+    free(m);
+    free(REQUEST);
+    free(SERVICE_URL);
+    return 0;
   }
-  //s[0]=s1;
+  close(saved_stdout);
 
 #ifdef DEBUG
@@ -483,11 +487,11 @@
     if(r_inputs==NULL) r_inputs=getMap(request_inputs,"RawDataOutput");
     
-    //#ifdef DEBUG
+#ifdef DEBUG
     fprintf(stderr,"OUTPUT Parsing ... \n");
-    //#endif
+#endif
     if(r_inputs!=NULL){
-      //#ifdef DEBUG
+#ifdef DEBUG
       fprintf(stderr,"OUTPUT Parsing start now ... \n");
-      //#endif
+#endif
       char current_output_as_string[10240];
       char cursor_output[10240];
@@ -765,7 +769,9 @@
 #endif
 	xmlNodePtr cur2=cur->children;
-	while(cur2){
-	  while(cur2->type!=XML_ELEMENT_NODE)
+	while(cur2!=NULL){
+	  while(cur2!=NULL && cur2->type!=XML_ELEMENT_NODE)
 	    cur2=cur2->next;
+	  if(cur2==NULL)
+	    break;
 	  /**
 	   * Indentifier
@@ -1024,8 +1030,9 @@
 #endif
 	    xmlNodePtr cur4=cur2->children;
-	    while(cur4){
-	      while(cur4->type!=XML_ELEMENT_NODE)
+	    while(cur4!=NULL){
+	      while(cur4!=NULL &&cur4->type!=XML_ELEMENT_NODE)
 		cur4=cur4->next;
-
+	      if(cur4==NULL)
+		break;
 	      if(xmlStrcasecmp(cur4->name, BAD_CAST "LiteralData")==0){
 		/**
@@ -1103,6 +1110,7 @@
 	dumpMaps(request_input_real_format);
 #endif
-	tmpmaps=tmpmaps->next;
-	      
+	freeMaps(&tmpmaps);
+	free(tmpmaps);
+	tmpmaps=NULL;	      
       }
 #ifdef DEBUG
@@ -1427,4 +1435,16 @@
   int eres=SERVICE_STARTED;
   int cpid=getpid();
+  
+  maps *_tmpMaps=(maps*)malloc(MAPS_SIZE);
+  _tmpMaps->name=strdup("lenv");
+  char tmpBuff[100];
+  sprintf(tmpBuff,"%i",cpid);
+  _tmpMaps->content=createMap("sid",tmpBuff);
+  _tmpMaps->next=NULL;
+  addToMap(_tmpMaps->content,"status","0");
+  addMapsToMaps(&m,_tmpMaps);
+  freeMaps(&_tmpMaps);
+  free(_tmpMaps);
+
 #ifdef DEBUG
   dumpMap(request_inputs);
@@ -1588,10 +1608,8 @@
     }
     else{
-#ifdef USE_PYTHON
       if(strncasecmp(r_inputs->value,"PYTHON",6)==0){
 	eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
       }
       else
-#endif
 	
 #ifdef USE_JAVA
@@ -1660,9 +1678,8 @@
       r_inputs=getMapFromMaps(m,"main","tmpPath");
       map* r_inputs1=getMap(s1->content,"ServiceProvider");
-      char* fbkp=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+16)*sizeof(char));
+      char* fbkp=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+100)*sizeof(char));
       sprintf(fbkp,"%s/%s_%d.xml",r_inputs->value,r_inputs1->value,cpid);
-      char* flog=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+22)*sizeof(char));
+      char* flog=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+100)*sizeof(char));
       sprintf(flog,"%s/%s_%d_error.log",r_inputs->value,r_inputs1->value,cpid);
-      fprintf(stderr,"File to use as backup %s\n",fbkp);
 #ifdef DEBUG
       fprintf(stderr,"RUN IN BACKGROUND MODE \n");
@@ -1675,4 +1692,6 @@
       free(fbkp);
       free(flog);
+      if(setsid()<0)
+	return errorException(m, "Unable to run the child process properly", "InternalError");
       /**
        * set status to SERVICE_STARTED and flush stdout to ensure full 
@@ -1681,6 +1700,7 @@
        * this way the data will be updated at the end of the process run.
        */
+      updateStatus(m);
       printProcessResponse(m,request_inputs,cpid,
-			    s1,r_inputs->value,SERVICE_STARTED,
+			    s1,r_inputs1->value,SERVICE_STARTED,
 			    request_input_real_format,
 			    request_output_real_format);
@@ -1810,11 +1830,8 @@
 	}
       } else{
-
-#ifdef USE_PYTHON
 	if(strncasecmp(r_inputs->value,"PYTHON",6)==0){
 	  eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
 	}
 	else
-#endif
 
 #ifdef USE_JAVA
@@ -1853,5 +1870,4 @@
       }
   
-      //res=execute(&m,&request_input_real_format,&request_output_real_format);
     } else {
       /**
@@ -1873,22 +1889,21 @@
 		   cpid,m,eres);
 
-  //if(getpid()==cpid){
+  if(((int)getpid())!=cpid){
+    fclose(stdout);
+    fclose(stderr);
+    unhandleStatus(m);
+  }
+
   freeService(&s1);
   free(s1);
   freeMaps(&m);
   free(m);
-  freeMaps(&tmpmaps);
-  free(tmpmaps);
   
   freeMaps(&request_input_real_format);
   free(request_input_real_format);
   
-  //freeMap(&request_inputs);
-  //free(request_inputs);
-    
   /* The following is requested but get issue using with Python support :/ */
   /* freeMaps(&request_output_real_format);
-     free(request_output_real_format);
-  */
+     free(request_output_real_format);*/
   
   free(REQUEST);
@@ -1899,5 +1914,4 @@
   fflush(stderr);
 #endif
-    //}
 
   return 0;
