title: Segmentation fault in Apache2 Module
body: <p>I'm currently reading the book "The Apache Modules Book" to learn writing Apache2 modules.
  I tried some examples from the book and in one case I get a segmentation fault, even if I completely copy&amp;paste the source file from the author's website. </p>
  
  <p>The example is an output filter that works on a request for a *.txt file, adds a html header and footer with the html-escaped content of the requested txt file in between.</p>
  
  <p>The sourcecode is available under: <a href="http://apache.webthing.com/mod_txt/" rel="nofollow">http://apache.webthing.com/mod_txt/</a></p>
  
  <p>The error in apache's log file is the following:</p>
  
  <blockquote>
    <p>[Thu Jan 12 20:38:01 2012] [notice] child pid 3500 exit signal
    Segmentation fault (11)</p>
  </blockquote>
  
  <p>I installed the module using the following commands:</p>
  
  <pre><code>apxs2 -c mod_txt.c 
  sudo apxs2 -i mod_txt.la 
  sudo service apache2 restart
  </code></pre>
  
  <p>There are no compile-errors when using apxs2.</p>
  
  <p>I added the Filter in the httpd.conf file as follows:</p>
  
  <pre><code>LoadModule txt_module /usr/lib/apache2/modules/mod_txt.so
  AddOutputFilter text-filter .txt
  AddType text/html .txt
  TextHeader /home/robert/header.txt
  TextFooter /home/robert/footer.txt
  </code></pre>
  
  <p>Is there anything wrong with the code or am I doing something wrong with comiling/installing/configuring the filter?</p>
  
  <p>My System: Ubuntu Lucid Lynx 10.04.3 with Apache 2.2.14 installed from the default Ubuntu repository.</p>
  
  <p>I'd really appreciate any hint on this!</p>
  
  <p>Thanks in advance!</p>
  
  <p>Best regards,
  Robert</p>
  
  <p>[Edit]
  Some additional information:</p>
  
  <p>I used gdb to get some more info on where the segfault happens. 
  Is there any way I can get the exact line number?</p>
  
  <p>This is the output:</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 0xab472b70 (LWP 4041)]
  0xb7d3fb9b in txt_filter () from /usr/lib/apache2/modules/mod_txt.so
  (gdb) bt
  #0  0xb7d3fb9b in txt_filter () from /usr/lib/apache2/modules/mod_txt.so
  #1  0x00154150 in ap_pass_brigade (next=0x2e3198, bb=0xb7f4fff4)
      at /build/buildd/apache2-2.2.14/server/util_filter.c:526
  #2  0x00141147 in default_handler (r=0x2e4ea8)
      at /build/buildd/apache2-2.2.14/server/core.c:3757
  #3  0x00148321 in ap_run_handler (r=0x2e4ea8)
      at /build/buildd/apache2-2.2.14/server/config.c:159
  #4  0x0014c107 in ap_invoke_handler (r=0x2e4ea8)
      at /build/buildd/apache2-2.2.14/server/config.c:373
  #5  0x0015b6b8 in ap_process_request (r=0x2e4ea8)
      at /build/buildd/apache2-2.2.14/modules/http/http_request.c:282
  #6  0x001581e8 in ap_process_http_connection (c=0x2defd0)
      at /build/buildd/apache2-2.2.14/modules/http/http_core.c:190
  #7  0x00150b91 in ap_run_process_connection (c=0x2defd0)
      at /build/buildd/apache2-2.2.14/server/connection.c:43
  #8  0x0016249b in process_socket (thd=0x2a7958, dummy=0x2dda00)
      at /build/buildd/apache2-2.2.14/server/mpm/worker/worker.c:544
  #9  worker_thread (thd=0x2a7958, dummy=0x2dda00)
      at /build/buildd/apache2-2.2.14/server/mpm/worker/worker.c:894
  #10 0xb7f781e1 in ?? () from /usr/lib/libapr-1.so.0
  #11 0xb7f3f96e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
  #12 0xb7eada4e in clone () from /lib/tls/i686/cmov/libc.so.6
  </code></pre>