pgagroal icon indicating copy to clipboard operation
pgagroal copied to clipboard

Reduce the number of error paths in configuration parsing

Open fluca1978 opened this issue 2 years ago • 0 comments

While working on #296 I saw that configuration.c has a few functions that have error paths like https://github.com/agroal/pgagroal/blob/master/src/libpgagroal/configuration.c#L1291:

error:

   free(master_key);
   free(password);
   free(decoded);

   if (file)
   {
      fclose(file);
   }

   return 1;

masterkey:

   free(master_key);
   free(password);
   free(decoded);

   if (file)
   {
      fclose(file);
   }

   return 2;

above:

   free(master_key);
   free(password);
   free(decoded);

   if (file)
   {
      fclose(file);
   }

   return 3;

The above error paths are identical except for the return value. Since it is safe to call free(3) on a null pointer, as it happens to be, and since the only change is on the return value, I propose to keep track of the return value and merge all the error paths into a single one to improve code readibility.

fluca1978 avatar Aug 11 '22 09:08 fluca1978