Jelajahi Sumber

lost: simplify freeing local variables on error

- the helper function has conditions inside

(cherry picked from commit 9f24f1109d6d491750c6feb19a9a6d0bcb674f90)
Daniel-Constantin Mierla 5 bulan lalu
induk
melakukan
b4030094f1
1 mengubah file dengan 9 tambahan dan 27 penghapusan
  1. 9 27
      src/modules/lost/functions.c

+ 9 - 27
src/modules/lost/functions.c

@@ -784,12 +784,8 @@ err:
 		xmlFreeDoc(doc);
 	}
 	/* clean up string */
-	if(res.s != NULL && res.len > 0) {
-		lost_free_string(&res);
-	}
-	if(err.s != NULL && err.len > 0) {
-		lost_free_string(&err);
-	}
+	lost_free_string(&res);
+	lost_free_string(&err);
 
 	return LOST_CLIENT_ERROR;
 }
@@ -1345,27 +1341,13 @@ err:
 	lost_free_geoheader_list(&geolist);
 	lost_free_loc(&loc);
 	/* clean up string */
-	if(oldurl.s != NULL && oldurl.len > 0) {
-		lost_free_string(&oldurl);
-	}
-	if(ret.s != NULL && ret.len > 0) {
-		lost_free_string(&ret);
-	}
-	if(req.s != NULL && req.len > 0) {
-		lost_free_string(&req);
-	}
-	if(rereq.s != NULL && rereq.len > 0) {
-		lost_free_string(&rereq);
-	}
-	if(name.s != NULL && name.len > 0) {
-		lost_free_string(&name);
-	}
-	if(uri.s != NULL && uri.len > 0) {
-		lost_free_string(&uri);
-	}
-	if(err.s != NULL && err.len > 0) {
-		lost_free_string(&err);
-	}
+	lost_free_string(&oldurl);
+	lost_free_string(&ret);
+	lost_free_string(&req);
+	lost_free_string(&rereq);
+	lost_free_string(&name);
+	lost_free_string(&uri);
+	lost_free_string(&err);
 
 	return LOST_CLIENT_ERROR;
 }