diff mbox

[RFC,10/33] job: Add job_delete()

Message ID 20180424152515.25664-11-kwolf@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kevin Wolf April 24, 2018, 3:24 p.m. UTC
This moves freeing the Job object and its fields from block_job_unref()
to job_delete().

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 include/qemu/job.h | 3 +++
 blockjob.c         | 3 +--
 job.c              | 6 ++++++
 3 files changed, 10 insertions(+), 2 deletions(-)

Comments

Eric Blake April 24, 2018, 10:15 p.m. UTC | #1
On 04/24/2018 10:24 AM, Kevin Wolf wrote:
> This moves freeing the Job object and its fields from block_job_unref()
> to job_delete().
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---

> +++ b/job.c
> @@ -56,3 +56,9 @@ void *job_create(const char *job_id, const JobDriver *driver, Error **errp)
>  
>      return job;
>  }
> +
> +void job_delete(Job *job)
> +{
> +    g_free(job->id);
> +    g_free(job);

Should this be free()-like, by being a no-op when NULL is passed in, on
the grounds that it might simplify some partial-construction error paths?
diff mbox

Patch

diff --git a/include/qemu/job.h b/include/qemu/job.h
index c87e951c8a..ee1f5d1ef4 100644
--- a/include/qemu/job.h
+++ b/include/qemu/job.h
@@ -62,6 +62,9 @@  struct JobDriver {
  */
 void *job_create(const char *job_id, const JobDriver *driver, Error **errp);
 
+/** Frees the @job object. */
+void job_delete(Job *job);
+
 /** Returns the JobType of a given Job. */
 JobType job_type(Job *job);
 
diff --git a/blockjob.c b/blockjob.c
index 5e766057e1..041a1e58d2 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -247,9 +247,8 @@  void block_job_unref(BlockJob *job)
                                         block_job_detach_aio_context, job);
         blk_unref(job->blk);
         error_free(job->blocker);
-        g_free(job->job.id);
         assert(!timer_pending(&job->sleep_timer));
-        g_free(job);
+        job_delete(&job->job);
     }
 }
 
diff --git a/job.c b/job.c
index f00f401502..a36425498d 100644
--- a/job.c
+++ b/job.c
@@ -56,3 +56,9 @@  void *job_create(const char *job_id, const JobDriver *driver, Error **errp)
 
     return job;
 }
+
+void job_delete(Job *job)
+{
+    g_free(job->id);
+    g_free(job);
+}