Browse code

lost: Coverity Scan fixes

(cherry picked from commit 328000233928fa08095889fdca7d66acba5e5825)

Wolfgang Kampichler authored on 25/04/2021 20:44:01
Showing 3 changed files
... ...
@@ -92,6 +92,9 @@ char *lost_held_type(char *type, int *exact, int *lgth)
92 92
 	int len = 0;
93 93
 
94 94
 	ret = (char *)pkg_malloc(1);
95
+	if(ret == NULL)
96
+		goto err;
97
+
95 98
 	memset(ret, 0, 1);
96 99
 	*lgth = 0;
97 100
 
... ...
@@ -269,7 +272,6 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
269 272
 	held = lost_new_held(did, rtype, held_resp_time, held_exact_type);
270 273
 	if(held == NULL) {
271 274
 		LM_ERR("held object allocation failed\n");
272
-		lost_free_string(&idhdr); /* clean up */
273 275
 		goto err;
274 276
 	}
275 277
 	que.s = lost_held_location_request(held, &que.len);
... ...
@@ -303,7 +305,7 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
303 305
 			/* is it a name or ip ... check nameinfo (reverse lookup) */
304 306
 			len = 0;
305 307
 			ipstr = lost_copy_string(host, &len);
306
-			if(ipstr != NULL && len > 0) {
308
+			if(ipstr != NULL) {
307 309
 				name.s = &(istr[0]);
308 310
 				name.len = NI_MAXHOST;
309 311
 				if(lost_get_nameinfo(ipstr, &name, flag) > 0) {
... ...
@@ -320,20 +322,18 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
320 322
 				}
321 323
 				pkg_free(ipstr); /* clean up */
322 324
 				ipstr = NULL;
325
+			} else {
326
+				LM_ERR("could not copy host info\n");
323 327
 			}
324 328
 			url.s = &(ustr[0]);
325 329
 			url.len = MAX_URI_SIZE;
326 330
 			if((naptr = lost_naptr_lookup(host, &sheld, &url)) == 0) {
327 331
 				LM_ERR("NAPTR failed on [%.*s]\n", host.len, host.s);
328
-				lost_free_string(&que); /* clean up */
329
-				lost_free_string(&idhdr);
330 332
 				goto err;
331 333
 			}
332 334
 		} else {
333 335
 			LM_ERR("failed to get location service for [%.*s]\n", did.len,
334 336
 					did.s);
335
-			lost_free_string(&que); /* clean up */
336
-			lost_free_string(&idhdr);
337 337
 			goto err;
338 338
 		}
339 339
 
... ...
@@ -342,21 +342,20 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
342 342
 		/* curl doesn't like str */
343 343
 		len = 0;
344 344
 		lisurl = lost_copy_string(url, &len);
345
-		/* send to service */
346
-		if(lisurl != NULL && len > 0) {
347
-			curl = httpapi.http_client_query_c(
348
-					_m, lisurl, &res, que.s, mtheld, ACCEPT_HDR);
349
-			pkg_free(lisurl); /*clean up */
350
-			lisurl = NULL;
351
-		} else {
345
+		if(lisurl == NULL) {
352 346
 			LM_ERR("could not copy POST url\n");
353 347
 			goto err;
354 348
 		}
349
+		/* send to service */
350
+		curl = httpapi.http_client_query_c(
351
+					_m, lisurl, &res, que.s, mtheld, ACCEPT_HDR);
352
+		pkg_free(lisurl); /*clean up */
353
+		lisurl = NULL;
355 354
 	}
356 355
 	/* only HTTP 2xx responses are accepted */
357 356
 	if(curl >= 300 || curl < 100) {
358 357
 		if(con.s != NULL && con.len > 0) {
359
-			LM_ERR("POST [%.*s] failed with error: %d\n", con.len, con.s, curl);
358
+			LM_ERR("[%.*s] failed with error: %d\n", con.len, con.s, curl);
360 359
 		} else {
361 360
 			LM_ERR("POST [%.*s] failed with error: %d\n", url.len, url.s, curl);
362 361
 		}
... ...
@@ -436,26 +435,22 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
436 435
 			} else {
437 436
 				len = 0;
438 437
 				heldreq = lost_held_post_request(&len, 0, NULL);
439
-				if(len > 0) {
440
-
441
-					LM_DBG("held POST request: [%.*s]\n", len, heldreq);
442
-
443
-					curl = httpapi.http_client_query_c(
444
-							_m, geo.s, &pidfurl, heldreq, mtheld, ACCEPT_HDR);
445
-					pkg_free(heldreq); /* clean up */
446
-					heldreq = NULL;
447
-				} else {
438
+				if(heldreq == NULL) {
448 439
 					LM_ERR("could not create POST request\n");
449
-					lost_free_string(&pidfurl); /* clean up */
450 440
 					goto err;
451 441
 				}
442
+				
443
+				LM_DBG("held POST request: [%.*s]\n", len, heldreq);
444
+
445
+				curl = httpapi.http_client_query_c(
446
+							_m, geo.s, &pidfurl, heldreq, mtheld, ACCEPT_HDR);
447
+				pkg_free(heldreq); /* clean up */
448
+				heldreq = NULL;
452 449
 			}
453 450
 			/* only HTTP 2xx responses are accepted */
454 451
 			if(curl >= 300 || curl < 100) {
455 452
 				LM_ERR("GET [%.*s] failed with error: %d\n", pidfurl.len,
456 453
 						pidfurl.s, curl);
457
-				/* clean up */
458
-				lost_free_string(&pidfurl);
459 454
 				goto err;
460 455
 			}
461 456
 			if(pidfurl.len == 0) {
... ...
@@ -470,7 +465,7 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
470 465
 				res.len = pidfurl.len;
471 466
 			}
472 467
 		}
473
-		/* error received */
468
+	/* error received */
474 469
 	} else if(xmlStrcmp(root->name, (const xmlChar *)"error") == 0) {
475 470
 
476 471
 		LM_DBG("HELD error response [%.*s]\n", res.len, res.s);
... ...
@@ -522,10 +517,15 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
522 517
 	return (err.len > 0) ? LOST_SERVER_ERROR : LOST_SUCCESS;
523 518
 
524 519
 err:
525
-	/* clean up */
520
+	/* clean up pointer */
521
+	lost_free_string(&que);
522
+    lost_free_string(&idhdr);
523
+	lost_free_string(&pidfurl);
524
+	/* clean up xml */
526 525
 	if(doc != NULL) {
527 526
 		xmlFreeDoc(doc);
528 527
 	}
528
+	/* clean up string */
529 529
 	if(res.s != NULL && res.len > 0) {
530 530
 		lost_free_string(&res);
531 531
 	}
... ...
@@ -600,10 +600,24 @@ int lost_held_dereference(struct sip_msg *_m, char *_url, char *_pidf,
600 600
 			goto err;
601 601
 		}
602 602
 		if(rtm.len == 0) {
603
+			/* default: rtime = 0 */
603 604
 			LM_WARN("no response time found\n");
604
-			ltime = 0;
605 605
 		} else {
606 606
 			ltime = strtol(rtm.s, &ptr, 10);
607
+			/* look for a number ... */
608
+			if((ltime > 0) && (strlen(ptr) == 0)) {
609
+				/* responseTime: milliseconds */
610
+				rtime = ltime;
611
+			/* or a string */ 
612
+			} else if((ltime == 0) && (strlen(ptr) > 0)) {
613
+				if(strncasecmp(ptr, HELD_ED, strlen(HELD_ED)) == 0) {
614
+					/* responseTime: emergencyDispatch */
615
+					rtime = -1;
616
+				} else if(strncasecmp(ptr, HELD_ER, strlen(HELD_ER)) == 0) {
617
+					/* responseTime: emergencyRouting */
618
+					rtime = 0;
619
+				}
620
+			}
607 621
 		}
608 622
 	}
609 623
 
... ...
@@ -620,26 +634,13 @@ int lost_held_dereference(struct sip_msg *_m, char *_url, char *_pidf,
620 634
 			len = 0;
621 635
 			/* response type string sanity check */
622 636
 			rtype = lost_held_type(rtp.s, &exact, &len);
623
-			if(len == 0) {
637
+			/* default value will be used if nothing was returned */
638
+			if(rtype == NULL) {
624 639
 				LM_WARN("cannot normalize [%.*s]\n", rtp.len, rtp.s);
625
-				rtype = NULL;
626 640
 			}
627 641
 		}
628 642
 	}
629 643
 
630
-	if((ltime > 0) && (strlen(ptr) == 0)) {
631
-		/* responseTime: milliseconds */
632
-		rtime = ltime;
633
-	} else if((ltime == 0) && (strlen(ptr) > 0)) {
634
-		if(strncasecmp(ptr, HELD_ED, strlen(HELD_ED)) == 0) {
635
-			/* responseTime: emergencyDispatch */
636
-			rtime = -1;
637
-		} else if(strncasecmp(ptr, HELD_ER, strlen(HELD_ER)) == 0) {
638
-			/* responseTime: emergencyRouting */
639
-			rtime = 0;
640
-		}
641
-	}
642
-
643 644
 	/* get the HELD request body */
644 645
 	heldreq = lost_held_post_request(&len, rtime, rtype);
645 646
 
... ...
@@ -649,7 +650,7 @@ int lost_held_dereference(struct sip_msg *_m, char *_url, char *_pidf,
649 650
 		rtype = NULL;
650 651
 	}
651 652
 
652
-	if(heldreq != NULL && len == 0) {
653
+	if(heldreq == NULL) {
653 654
 		LM_ERR("could not create POST request\n");
654 655
 		goto err;
655 656
 	}
... ...
@@ -659,23 +660,22 @@ int lost_held_dereference(struct sip_msg *_m, char *_url, char *_pidf,
659 660
 	/* curl doesn't like str */
660 661
 	len = 0;
661 662
 	lisurl = lost_copy_string(url, &len);
662
-	if(lisurl != NULL && len > 0) {
663
-
664
-		LM_DBG("POST url: [%.*s]\n", len, lisurl);
665
-
666
-		curl = httpapi.http_client_query_c(
667
-				_m, lisurl, &res, heldreq, mtheld, ACCEPT_HDR);
668
-		pkg_free(lisurl); /* clean up */
669
-		lisurl = NULL;
670
-		pkg_free(heldreq);
671
-		heldreq = NULL;
672
-	} else {
663
+	if(lisurl == NULL) {
673 664
 		LM_ERR("could not copy POST url\n");
674 665
 		pkg_free(heldreq); /* clean up */
675 666
 		heldreq = NULL;
676 667
 		goto err;
677 668
 	}
678 669
 
670
+	LM_DBG("POST url: [%.*s]\n", len, lisurl);
671
+
672
+	curl = httpapi.http_client_query_c(
673
+				_m, lisurl, &res, heldreq, mtheld, ACCEPT_HDR);
674
+	pkg_free(lisurl); /* clean up */
675
+	lisurl = NULL;
676
+	pkg_free(heldreq);
677
+	heldreq = NULL;
678
+
679 679
 	/* only HTTP 2xx responses are accepted */
680 680
 	if(curl >= 300 || curl < 100) {
681 681
 		LM_ERR("POST [%.*s] failed with error: %d\n", url.len, url.s, curl);
... ...
@@ -757,10 +757,11 @@ int lost_held_dereference(struct sip_msg *_m, char *_url, char *_pidf,
757 757
 	return (err.len > 0) ? LOST_SERVER_ERROR : LOST_SUCCESS;
758 758
 
759 759
 err:
760
-	/* clean up */
760
+	/* clean up xml */
761 761
 	if(doc != NULL) {
762 762
 		xmlFreeDoc(doc);
763 763
 	}
764
+	/* clean up string */
764 765
 	if(res.s != NULL && res.len > 0) {
765 766
 		lost_free_string(&res);
766 767
 	}
... ...
@@ -989,18 +990,17 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
989 990
 			} else {
990 991
 				len = 0;
991 992
 				heldreq = lost_held_post_request(&len, 0, NULL);
992
-				if(len > 0) {
993
-
994
-					LM_DBG("POST request: [%.*s]\n", len, heldreq);
995
-
996
-					curl = httpapi.http_client_query_c(
997
-							_m, url.s, &ret, heldreq, mtheld, ACCEPT_HDR);
998
-					pkg_free(heldreq); /* clean up */
999
-					heldreq = NULL;
1000
-				} else {
993
+				if(heldreq == NULL) {
1001 994
 					LM_ERR("could not create POST request\n");
1002 995
 					goto err;
1003 996
 				}
997
+
998
+				LM_DBG("POST request: [%.*s]\n", len, heldreq);
999
+
1000
+				curl = httpapi.http_client_query_c(
1001
+							_m, url.s, &ret, heldreq, mtheld, ACCEPT_HDR);
1002
+				pkg_free(heldreq); /* clean up */
1003
+				heldreq = NULL;
1004 1004
 			}
1005 1005
 			/* only HTTP 2xx responses are accepted */
1006 1006
 			if(curl >= 300 || curl < 100) {
... ...
@@ -1059,15 +1059,14 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
1059 1059
 		/* copy url */
1060 1060
 		len = 0;
1061 1061
 		urlrep = lost_copy_string(url, &len);
1062
-		if(urlrep != NULL && len > 0) {
1063
-			/* send request */
1064
-			curl = httpapi.http_client_query(_m, urlrep, &ret, req.s, mtlost);
1065
-			pkg_free(urlrep); /* clean up */
1066
-			urlrep = NULL;
1067
-		} else {
1062
+		if(urlrep == NULL) {
1068 1063
 			LM_ERR("could not copy POST url\n");
1069 1064
 			goto err;
1070 1065
 		}
1066
+		/* send request */
1067
+		curl = httpapi.http_client_query(_m, urlrep, &ret, req.s, mtlost);
1068
+		pkg_free(urlrep); /* clean up */
1069
+		urlrep = NULL;
1071 1070
 	} else {
1072 1071
 		curl = httpapi.http_connect(_m, &con, NULL, &ret, mtlost, &req);
1073 1072
 	}
... ...
@@ -1076,7 +1075,7 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
1076 1075
 		if(naptr) {
1077 1076
 			LM_ERR("POST [%.*s] failed with error: %d\n", url.len, url.s, curl);
1078 1077
 		} else {
1079
-			LM_ERR("POST [%.*s] failed with error: %d\n", con.len, con.s, curl);
1078
+			LM_ERR("[%.*s] failed with error: %d\n", con.len, con.s, curl);
1080 1079
 		}
1081 1080
 		lost_free_string(&ret);
1082 1081
 		goto err;
... ...
@@ -1160,11 +1159,13 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
1160 1159
 						tmp.len = strlen(fsrdata->redirect->target);
1161 1160
 						url.s = &(ustr[0]);
1162 1161
 						url.len = MAX_URI_SIZE;
1162
+						/* get url string via NAPTR */
1163 1163
 						naptr = lost_naptr_lookup(tmp, &shttps, &url);
1164 1164
 						if(naptr == 0) {
1165 1165
 							/* fallback to http */
1166 1166
 							naptr = lost_naptr_lookup(tmp, &shttp, &url);
1167 1167
 						}
1168
+						/* nothing found ... return */
1168 1169
 						if(naptr == 0) {
1169 1170
 							LM_ERR("NAPTR failed on [%.*s]\n", tmp.len, tmp.s);
1170 1171
 							goto err;
... ...
@@ -1192,24 +1193,24 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
1192 1193
 						/* copy url */
1193 1194
 						len = 0;
1194 1195
 						urlrep = lost_copy_string(url, &len);
1195
-						if(urlrep != NULL && len > 0) {
1196
-							/* send request */
1197
-							curl = httpapi.http_client_query(
1198
-									_m, urlrep, &ret, req.s, mtlost);
1199
-							url.s = NULL;
1200
-							url.len = 0;
1201
-							pkg_free(urlrep); /*clean up */
1202
-							urlrep = NULL;
1203
-							/* only HTTP 2xx responses are accepted */
1204
-							if(curl >= 300 || curl < 100) {
1205
-								LM_ERR("POST [%.*s] failed with error: %d\n",
1206
-									url.len, url.s, curl);
1207
-								goto err;
1208
-							}
1209
-						} else {
1196
+						if(urlrep == NULL) {
1210 1197
 							LM_ERR("could not copy POST url\n");
1211 1198
 							goto err;
1212 1199
 						}
1200
+						/* send request */
1201
+						curl = httpapi.http_client_query(
1202
+								_m, urlrep, &ret, req.s, mtlost);
1203
+						pkg_free(urlrep); /*clean up */
1204
+						urlrep = NULL;
1205
+						/* only HTTP 2xx responses are accepted */
1206
+						if(curl >= 300 || curl < 100) {
1207
+							LM_ERR("POST [%.*s] failed with error: %d\n",
1208
+								url.len, url.s, curl);
1209
+							goto err;
1210
+						}
1211
+						/* reset url string */
1212
+						url.s = NULL;
1213
+						url.len = 0;
1213 1214
 						/* once more ... we got a redirect */
1214 1215
 						redirect = 1;
1215 1216
 					}
... ...
@@ -1268,6 +1269,7 @@ err:
1268 1269
 	lost_free_findServiceResponse(&fsrdata);
1269 1270
 	lost_free_geoheader_list(&geolist);
1270 1271
 	lost_free_loc(&loc);
1272
+	/* clean up string */
1271 1273
 	if(oldurl.s != NULL && oldurl.len > 0) {
1272 1274
 		lost_free_string(&oldurl);
1273 1275
 	}
... ...
@@ -566,7 +566,6 @@ p_lost_issue_t lost_get_response_issues(xmlNodePtr node)
566 566
 
567 567
 	if(node == NULL) {
568 568
 		return NULL;
569
-		;
570 569
 	}
571 570
 
572 571
 	LM_DBG("### LOST\t%s\n", node->name);
... ...
@@ -574,19 +573,13 @@ p_lost_issue_t lost_get_response_issues(xmlNodePtr node)
574 573
 	cur = node->children;
575 574
 	while(cur) {
576 575
 		if(cur->type == XML_ELEMENT_NODE) {
577
-			/* get a new list element */
578
-			new = lost_new_response_issues();
579
-			if(new == NULL) {
580
-				return NULL;
581
-			}
582
-			/* parse the element */
576
+			/* get a new response type element */
583 577
 			issue = lost_new_response_type();
584 578
 			if(issue == NULL) {
585
-				PKG_MEM_ERROR;
586
-				pkg_free(list);
587
-				pkg_free(new);
588
-				return NULL;
579
+				/* didn't get it ... return */
580
+				break;
589 581
 			}
582
+			/* parse properties */
590 583
 			issue->source = lost_get_property(cur->parent, MAPP_PROP_SRC, &len);
591 584
 			tmp.s = (char *)cur->name;
592 585
 			tmp.len = strlen((char *)cur->name);
... ...
@@ -601,12 +594,17 @@ p_lost_issue_t lost_get_response_issues(xmlNodePtr node)
601 594
 					issue->info->text = lost_get_property(cur, PROP_MSG, &len);
602 595
 					issue->info->lang = lost_get_property(cur, PROP_LANG, &len);
603 596
 				}
597
+				/* get a new list element */
598
+				new = lost_new_response_issues();
599
+				if(new == NULL) {
600
+					/* didn't get it, delete response type element ... return */
601
+					lost_delete_response_type(&issue); /* clean up */
602
+					break;
603
+				}
604 604
 				/* append to list */
605 605
 				new->issue = issue;
606 606
 				new->next = list;
607 607
 				list = new;
608
-			} else {
609
-				lost_delete_response_issues(&new); /* clean up */
610 608
 			}
611 609
 			/* get next element */
612 610
 			cur = cur->next;
... ...
@@ -272,20 +272,19 @@ void lost_free_held(p_lost_held_t *held)
272 272
 char *lost_copy_string(str src, int *lgth)
273 273
 {
274 274
 	char *res = NULL;
275
+	*lgth = 0;
275 276
 
276
-	if(src.s == NULL && src.len == 0) {
277
-		*lgth = 0;
278
-		return NULL;
279
-	}
280
-	res = (char *)pkg_malloc((src.len + 1) * sizeof(char));
281
-	if(res == NULL) {
282
-		PKG_MEM_ERROR;
283
-		*lgth = 0;
284
-	} else {
285
-		memset(res, 0, src.len + 1);
286
-		memcpy(res, src.s, src.len);
287
-		res[src.len] = '\0';
288
-		*lgth = (int)strlen(res);
277
+	/* only copy a valid string */
278
+	if(src.s != NULL && src.len > 0) {
279
+		res = (char *)pkg_malloc((src.len + 1) * sizeof(char));
280
+		if(res == NULL) {
281
+			PKG_MEM_ERROR;
282
+		} else {
283
+			memset(res, 0, src.len + 1);
284
+			memcpy(res, src.s, src.len);
285
+			res[src.len] = '\0';
286
+			*lgth = (int)strlen(res);
287
+		}
289 288
 	}
290 289
 
291 290
 	return res;
... ...
@@ -590,7 +589,7 @@ int lost_parse_host(const char *uri, str *host, int *flag)
590 589
 	host->len = end - search;
591 590
 
592 591
 	if(ip6) {
593
-		*flag = AF_INET;
592
+		*flag = AF_INET6;
594 593
 	} else {
595 594
 		*flag = AF_INET;
596 595
 	}
... ...
@@ -1194,7 +1193,7 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_lost_loc_t loc)
1194 1193
 				/* nothing found */
1195 1194
 				if((select < 0) && (i == size - 1)) {
1196 1195
 					LM_ERR("could not find proper location-info element\n");
1197
-					xmlFree(xmlbuff);
1196
+					xmlFree(xmlbuff); /* clean up */
1198 1197
 					xmlFreeDoc(new);
1199 1198
 					xmlXPathFreeObject(result);
1200 1199
 					return -1;
... ...
@@ -1202,22 +1201,28 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_lost_loc_t loc)
1202 1201
 
1203 1202
 				if(i == select) {
1204 1203
 					/* return the current profile */
1205
-					loc->profile = (char *)pkg_malloc(strlen(s_profile) + 1);
1206
-					if(loc->profile == NULL) {
1207
-						xmlFree(xmlbuff);
1204
+					if(s_profile != NULL) {
1205
+						loc->profile = (char *)pkg_malloc(strlen(s_profile) + 1);
1206
+						if(loc->profile == NULL) {
1207
+							xmlFree(xmlbuff); /* clean up */
1208
+							xmlFreeDoc(new);
1209
+							xmlXPathFreeObject(result);
1210
+							goto err;
1211
+						}
1212
+						memset(loc->profile, 0, strlen(s_profile) + 1);
1213
+						memcpy(loc->profile, s_profile, strlen(s_profile));
1214
+					} else {
1215
+						xmlFree(xmlbuff); /* clean up */
1208 1216
 						xmlFreeDoc(new);
1209 1217
 						xmlXPathFreeObject(result);
1210 1218
 						goto err;
1211 1219
 					}
1212
-					memset(loc->profile, 0, strlen(s_profile) + 1);
1213
-					memcpy(loc->profile, s_profile, strlen(s_profile));
1214
-
1215 1220
 					/* remove xml header from location element */
1216 1221
 					remove = strlen("<?xml version='1.0'?>\n");
1217 1222
 					buffersize = buffersize - remove;
1218 1223
 					ptr = (char *)pkg_malloc((buffersize + 1) * sizeof(char));
1219 1224
 					if(ptr == NULL) {
1220
-						xmlFree(xmlbuff);
1225
+						xmlFree(xmlbuff); /* clean up */
1221 1226
 						xmlFreeDoc(new);
1222 1227
 						xmlXPathFreeObject(result);
1223 1228
 						goto err;
... ...
@@ -1233,7 +1238,7 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_lost_loc_t loc)
1233 1238
 					/* return the location DOM */
1234 1239
 					loc->xpath = (char *)pkg_malloc(len + 1);
1235 1240
 					if(loc->xpath == NULL) {
1236
-						pkg_free(ptr);
1241
+						pkg_free(ptr); /* clean up */
1237 1242
 						ptr = NULL;
1238 1243
 						xmlFree(xmlbuff);
1239 1244
 						xmlFreeDoc(new);
... ...
@@ -1242,8 +1247,7 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_lost_loc_t loc)
1242 1247
 					}
1243 1248
 					memset(loc->xpath, 0, len + 1);
1244 1249
 					memcpy(loc->xpath, tmp, len);
1245
-					/* free memory */
1246
-					pkg_free(ptr);
1250
+					pkg_free(ptr); /* clean up */
1247 1251
 					ptr = NULL;
1248 1252
 				} else {
1249 1253
 					LM_WARN("xpath location-info element(%d) ignored\n", i + 1);