[Mesa-dev] [PATCH 4/4] intel: aubinator: Fix memory leaks
Lionel Landwerlin
lionel.g.landwerlin at intel.com
Wed Sep 5 17:34:21 UTC 2018
On 05/09/2018 18:19, Sagar Ghuge wrote:
> Signed-off-by: Sagar Ghuge <sagar.ghuge at intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
> ---
> src/intel/tools/aubinator.c | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/src/intel/tools/aubinator.c b/src/intel/tools/aubinator.c
> index 55672fa073..ef0f7650b1 100644
> --- a/src/intel/tools/aubinator.c
> +++ b/src/intel/tools/aubinator.c
> @@ -95,6 +95,18 @@ aubinator_init(void *user_data, int aub_pci_id, const char *app_name)
>
> gen_batch_decode_ctx_init(&batch_ctx, &devinfo, outfile, batch_flags,
> xml_path, NULL, NULL, NULL);
> +
> + /* Check for valid spec instance, if wrong xml_path is passed then spec
> + * instance is not initialized properly
> + */
> + if (!batch_ctx.spec) {
> + fprintf(stderr, "Failed to initialize gen_batch_decode_ctx "
> + "spec instance\n");
> + free(xml_path);
> + gen_batch_decode_ctx_finish(&batch_ctx);
> + exit(EXIT_FAILURE);
> + }
> +
> batch_ctx.max_vbo_decoded_lines = max_vbo_lines;
>
> char *color = GREEN_HEADER, *reset_color = NORMAL;
> @@ -178,14 +190,19 @@ aub_file_open(const char *filename)
> int fd;
>
> file = calloc(1, sizeof *file);
> + if (file == NULL)
> + return NULL;
> +
> fd = open(filename, O_RDONLY);
> if (fd == -1) {
> fprintf(stderr, "open %s failed: %s\n", filename, strerror(errno));
> + free(file);
> exit(EXIT_FAILURE);
> }
>
> if (fstat(fd, &sb) == -1) {
> fprintf(stderr, "stat failed: %s\n", strerror(errno));
> + free(file);
> exit(EXIT_FAILURE);
> }
>
> @@ -193,6 +210,7 @@ aub_file_open(const char *filename)
> PROT_READ, MAP_SHARED, fd, 0);
> if (file->map == MAP_FAILED) {
> fprintf(stderr, "mmap failed: %s\n", strerror(errno));
> + free(file);
> exit(EXIT_FAILURE);
> }
>
> @@ -333,6 +351,11 @@ int main(int argc, char *argv[])
> }
>
> file = aub_file_open(input_file);
> + if (!file) {
> + fprintf(stderr, "Unable to allocate buffer to open aub file\n");
> + free(xml_path);
> + exit(EXIT_FAILURE);
> + }
>
> struct aub_read aub_read = {
> .user_data = &mem,
> @@ -359,9 +382,11 @@ int main(int argc, char *argv[])
> fflush(stdout);
> /* close the stdout which is opened to write the output */
> close(1);
> + free(file);
> free(xml_path);
>
> wait(NULL);
> + gen_batch_decode_ctx_finish(&batch_ctx);
>
> return EXIT_SUCCESS;
> }
More information about the mesa-dev
mailing list