瀏覽代碼

dpkg: Only allocate STATOVERRIDEFILE and DIVERSIONSFILE paths once

There's no point in reallocating these on every function invocation,
if in the future we need to change the paths between calls, then the
function can be reworked to take a pathname for example.
Guillem Jover 12 年之前
父節點
當前提交
3e05efebd3
共有 2 個文件被更改,包括 4 次插入6 次删除
  1. 2 3
      src/divertdb.c
  2. 2 3
      src/statdb.c

+ 2 - 3
src/divertdb.c

@@ -52,9 +52,8 @@ ensure_diversions(void)
 	FILE *file;
 	struct diversion *ov, *oicontest, *oialtname;
 
-	if (diversionsname != NULL)
-		free(diversionsname);
-	diversionsname = dpkg_db_get_path(DIVERSIONSFILE);
+	if (diversionsname == NULL)
+		diversionsname = dpkg_db_get_path(DIVERSIONSFILE);
 
 	onerr_abort++;
 

+ 2 - 3
src/statdb.c

@@ -117,9 +117,8 @@ ensure_statoverrides(void)
 	struct file_stat *fso;
 	struct filenamenode *fnn;
 
-	if (statoverridename != NULL)
-		free(statoverridename);
-	statoverridename = dpkg_db_get_path(STATOVERRIDEFILE);
+	if (statoverridename == NULL)
+		statoverridename = dpkg_db_get_path(STATOVERRIDEFILE);
 
 	onerr_abort++;