[ 
https://issues.apache.org/jira/browse/AVRO-2026?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16715406#comment-16715406
 ] 

ASF GitHub Bot commented on AVRO-2026:
--------------------------------------

dkulp closed pull request #218: AVRO-2026: Add valgrind to c tests
URL: https://github.com/apache/avro/pull/218
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lang/c/build.sh b/lang/c/build.sh
index f76f03550..cf05c1367 100755
--- a/lang/c/build.sh
+++ b/lang/c/build.sh
@@ -61,7 +61,6 @@ case "$1" in
     prepare_build
     make -C $build_dir
     make -C $build_dir test
-    clean
     ;;
 
   dist)
diff --git a/lang/c/tests/CMakeLists.txt b/lang/c/tests/CMakeLists.txt
index 445e689a7..b885d28ca 100644
--- a/lang/c/tests/CMakeLists.txt
+++ b/lang/c/tests/CMakeLists.txt
@@ -40,27 +40,45 @@ macro(add_avro_test name)
     )
 endmacro(add_avro_test)
 
+macro(add_avro_test_checkmem name)
+    add_avro_test(${name} ${ARGN})
+    if(UNIX)
+        find_program(MEMORYCHECK_COMMAND valgrind )
+        if(MEMORYCHECK_COMMAND)
+            add_test(memcheck_${name}
+                ${CMAKE_COMMAND} -E chdir ${AvroC_SOURCE_DIR}/tests
+                ${MEMORYCHECK_COMMAND}
+                    --log-file=${CMAKE_CURRENT_BINARY_DIR}/memcheck_${name}.log
+                    --leak-check=full
+                    --show-reachable=yes
+                    --error-exitcode=1
+                    ${exec_name}
+            )
+        endif(MEMORYCHECK_COMMAND)
+    endif (UNIX)
+endmacro(add_avro_test_checkmem)
+
 add_avro_executable(generate_interop_data)
 add_avro_executable(performance)
 add_avro_executable(test_interop_data)
 
-add_avro_test(test_data_structures)
-add_avro_test(test_avro_schema)
-add_avro_test(test_avro_schema_names)
-add_avro_test(test_avro_values)
-add_avro_test(test_avro_968)
-add_avro_test(test_avro_984)
-add_avro_test(test_avro_1034)
-add_avro_test(test_avro_1084)
-add_avro_test(test_avro_1087)
-add_avro_test(test_avro_1165)
-add_avro_test(test_avro_1237)
-add_avro_test(test_avro_1238)
-add_avro_test(test_avro_1279)
-add_avro_test(test_avro_1405)
-add_avro_test(test_avro_1572)
-add_avro_test(test_avro_data)
-add_avro_test(test_refcount)
-add_avro_test(test_cpp test_cpp.cpp)
-add_avro_test(test_avro_1379)
-add_avro_test(test_avro_1691)
+add_avro_test_checkmem(test_data_structures)
+add_avro_test_checkmem(test_avro_schema)
+add_avro_test_checkmem(test_avro_schema_names)
+add_avro_test_checkmem(test_avro_values)
+add_avro_test_checkmem(test_avro_968)
+add_avro_test_checkmem(test_avro_984)
+add_avro_test_checkmem(test_avro_1034)
+add_avro_test_checkmem(test_avro_1084)
+add_avro_test_checkmem(test_avro_1087)
+add_avro_test_checkmem(test_avro_1165)
+add_avro_test_checkmem(test_avro_1237)
+add_avro_test_checkmem(test_avro_1238)
+add_avro_test_checkmem(test_avro_1279)
+add_avro_test_checkmem(test_avro_1405)
+add_avro_test_checkmem(test_avro_1572)
+add_avro_test(test_avro_data) # Skip memory check for datum. Deprecated and 
has a lot of memory issues
+add_avro_test_checkmem(test_refcount)
+add_avro_test_checkmem(test_cpp test_cpp.cpp)
+add_avro_test_checkmem(test_avro_1379)
+add_avro_test_checkmem(test_avro_1691)
diff --git a/lang/c/tests/test_avro_1034.c b/lang/c/tests/test_avro_1034.c
index 036337ae4..957f30158 100644
--- a/lang/c/tests/test_avro_1034.c
+++ b/lang/c/tests/test_avro_1034.c
@@ -37,18 +37,18 @@
  * resolved_reader_class and a corresponding resolved_record instance
  * is created (using identical "writer" and "reader" schemas for
  * simplicity), and an attempt is made to "read" the resolved avro
- * value. 
- * 
+ * value.
+ *
  * Once the resolved value has been read, the source value (nested)
  * and the resolved value (resolved_record) are both reset using
  * avro_value_reset(). Then the source value (nested) is populated
  * with another (larger) nested array. Then an attempt is made to read
  * the resolved avro value again.
- * 
+ *
  * This second attempt to read the resolved value results in a
- * segmentation fault under Linux, using the patch in 
+ * segmentation fault under Linux, using the patch in
  * 
https://issues.apache.org/jira/secure/attachment/12516487/0001-AVRO-1034.-C-Resolved-reader-initializes-child-array.patch.
- * 
+ *
  * However, the program does not seg fault, using the patch in
  * https://issues.apache.org/jira/secure/attachment/12515544/AVRO-1034.patch
  *
@@ -281,11 +281,12 @@ int add_array( avro_writer_t writer,
 
     try ( avro_value_write( writer, &resolved_record ),
           "Unable to write record into memory using writer_record" );
-    
+
     print_array_fields( &resolved_record );
 
     avro_value_decref( &resolved_record );
     avro_value_iface_decref( writer_class );
+    avro_value_iface_decref( resolved_reader_class );
   }
   else
   {
diff --git a/lang/c/tests/test_avro_1087.c b/lang/c/tests/test_avro_1087.c
index c6aa80772..4639a2998 100644
--- a/lang/c/tests/test_avro_1087.c
+++ b/lang/c/tests/test_avro_1087.c
@@ -30,9 +30,9 @@ avro_schema_t schema;
 
 void add_record (avro_file_writer_t writer)
 {
-       avro_datum_t main_datum = avro_record(schema);          
+       avro_datum_t main_datum = avro_record(schema);
        avro_datum_t id_datum = avro_int32(1);
-       
+
        if (avro_record_set (main_datum, "ID", id_datum))
        {
                printf ("Unable to create datum");
@@ -76,10 +76,12 @@ int main()
 
        avro_file_writer_open (dbname, &writer);
        add_record (writer);
-       
+
        avro_file_writer_flush (writer);
        avro_file_writer_close (writer);
 
+    avro_schema_decref(schema);
+
        remove (dbname);
 
        return EXIT_SUCCESS;
diff --git a/lang/c/tests/test_avro_1379.c b/lang/c/tests/test_avro_1379.c
index 738a0bdd5..eeeac5a1d 100644
--- a/lang/c/tests/test_avro_1379.c
+++ b/lang/c/tests/test_avro_1379.c
@@ -119,5 +119,11 @@ int main(void)
        check(rval, avro_file_reader_close(file_reader));
        remove(outpath);
 
+       avro_writer_free(writer);
+       avro_value_decref(&out);
+       avro_value_decref(&val);
+       avro_value_iface_decref(iface);
+       avro_schema_decref(schema);
+
        exit(EXIT_SUCCESS);
 }
diff --git a/lang/c/tests/test_avro_1691.c b/lang/c/tests/test_avro_1691.c
index 455f2cb62..2d0c99f5b 100644
--- a/lang/c/tests/test_avro_1691.c
+++ b/lang/c/tests/test_avro_1691.c
@@ -88,6 +88,12 @@ int main(void)
                 fprintf(stderr, "pass %d: ok: schema %s\n", pass, json_schema);
                 check(rval, avro_file_reader_close(file_reader));
                 remove(outpath);
+                
+                avro_writer_free(writer);
+                avro_value_decref(&out);
+                avro_value_decref(&val);
+                avro_value_iface_decref(iface);
+                avro_schema_decref(schema);
         }
 
        exit(EXIT_SUCCESS);
diff --git a/share/docker/Dockerfile b/share/docker/Dockerfile
index 01760554d..cedfefcc7 100644
--- a/share/docker/Dockerfile
+++ b/share/docker/Dockerfile
@@ -35,7 +35,8 @@ RUN apt-get update && apt-get install --no-install-recommends 
-y \
   php5 phpunit php5-gmp bzip2 \
   python python-setuptools python3-setuptools \
   ruby ruby-dev rake \
-  libsnappy1 libsnappy-dev
+  libsnappy1 libsnappy-dev \
+  valgrind
 
 # Install Forrest
 RUN mkdir -p /usr/local/apache-forrest


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Incorporate valgrind memory testing for C
> -----------------------------------------
>
>                 Key: AVRO-2026
>                 URL: https://issues.apache.org/jira/browse/AVRO-2026
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: c
>            Reporter: John Gill
>            Priority: Major
>             Fix For: 1.8.3
>
>         Attachments: AVRO-2026.patch
>
>
> With the work done for AVRO-1167 & AVRO-766 in identifying memory leaks 
> decided to make it a standard part of the testing framework. This issue  
> requires https://github.com/apache/avro/pull/218 otherwise test_avro_schema 
> and test_avro_values fail due to to avro_schema_copy calls.
> Adding valgrind tool to the docker container
> Adding valgrind to CMakeLists.txt to optionally do valgrind testing if the 
> tool is found
> Cleaning up existing tests that were failing due to not properly cleaning up 
> memory
> Lastly, as part of ./build.sh test for lang/c do not remove the build/c 
> directory. The memcheck output is kept so that memory leak issues can be 
> reviewed and addressed.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to