serf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhuij...@apache.org
Subject svn commit: r1710989 - in /serf/trunk: buckets/aggregate_buckets.c test/test_buckets.c
Date Wed, 28 Oct 2015 10:55:01 GMT
Author: rhuijben
Date: Wed Oct 28 10:55:01 2015
New Revision: 1710989

URL: http://svn.apache.org/viewvc?rev=1710989&view=rev
Log:
Resolve a minor memory leak in the aggregate bucket's read_bucket
implementation.

* buckets/aggregate_buckets.c
  (serf_bucket_aggregate_append_iovec):
      Resolve warning by commenting unused var.

  (serf_aggregate_read_bucket):
      Properly release item that contained the pointer to the
      released bucket.

* test/test_buckets.c
  (test_aggregate_buckets): Extend test to test reading a bucket
      from the aggregate.

Modified:
    serf/trunk/buckets/aggregate_buckets.c
    serf/trunk/test/test_buckets.c

Modified: serf/trunk/buckets/aggregate_buckets.c
URL: http://svn.apache.org/viewvc/serf/trunk/buckets/aggregate_buckets.c?rev=1710989&r1=1710988&r2=1710989&view=diff
==============================================================================
--- serf/trunk/buckets/aggregate_buckets.c (original)
+++ serf/trunk/buckets/aggregate_buckets.c Wed Oct 28 10:55:01 2015
@@ -227,7 +227,7 @@ void serf_bucket_aggregate_append_iovec(
     struct iovec *vecs,
     int vecs_count)
 {
-    aggregate_context_t *ctx = aggregate_bucket->data;
+    /* aggregate_context_t *ctx = aggregate_bucket->data; */
     serf_bucket_t *new_bucket;
 
     new_bucket = serf_bucket_iovec_create(vecs, vecs_count,
@@ -475,15 +475,21 @@ static serf_bucket_t * serf_aggregate_re
 {
     aggregate_context_t *ctx = bucket->data;
     serf_bucket_t *found_bucket;
+    bucket_list_t *list;
 
     if (!ctx->list) {
         return NULL;
     }
 
-    if (ctx->list->bucket->type == type) {
+    list = ctx->list;
+    if (list->bucket->type == type) {
         /* Got the bucket. Consume it from our list. */
-        found_bucket = ctx->list->bucket;
-        ctx->list = ctx->list->next;
+        found_bucket = list->bucket;
+        ctx->list = list->next;
+
+        /* And destroy the now unused item */
+        serf_bucket_mem_free(bucket->allocator, list);
+
         return found_bucket;
     }
 

Modified: serf/trunk/test/test_buckets.c
URL: http://svn.apache.org/viewvc/serf/trunk/test/test_buckets.c?rev=1710989&r1=1710988&r2=1710989&view=diff
==============================================================================
--- serf/trunk/test/test_buckets.c (original)
+++ serf/trunk/test/test_buckets.c Wed Oct 28 10:55:01 2015
@@ -674,6 +674,24 @@ static void test_aggregate_buckets(CuTes
              len > 0 && len <= strlen(BODY) );
     CuAssert(tc, "Data should match first part of body.",
              strncmp(BODY, data, len) == 0);
+
+    aggbkt = serf_bucket_aggregate_create(alloc);
+
+    /* Put bkt in the aggregate */
+    bkt = SERF_BUCKET_SIMPLE_STRING(BODY, alloc);
+    serf_bucket_aggregate_append(aggbkt, bkt);
+
+    /* And now remove it */
+    CuAssertPtrEquals(tc, bkt,
+                      serf_bucket_read_bucket(aggbkt,
+                                              &serf_bucket_type_simple));
+    /* Ok, then aggregate should be empty */
+    read_and_check_bucket(tc, aggbkt, "");
+    /* And can be destroyed */
+    serf_bucket_destroy(aggbkt);
+    /* While it doesn't affect the inner bucket */
+    read_and_check_bucket(tc, bkt, BODY);
+    serf_bucket_destroy(bkt);
 }
 
 static void test_aggregate_bucket_readline(CuTest *tc)



Mime
View raw message