Просмотр исходного кода

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
Родитель
Сommit
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++;