You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Chris London <ch...@kwista.com> on 2011/08/24 23:59:58 UTC

My first Apache module!

Hey everyone,

I don't like to bother mailing lists with beginner questions so I spent
a few hours on Google looking for info and tutorials. I'm sure at least one
of you has had that experience :) Anyway, I have finished my first module
and it works exactly how I want it to.  I still have more features I want to
add but I'm a little rusty with my C and even worse at Apache Modules. Would
you mind taking a glance at my code to see if I'm doing anything wrong or
have any memory leaks or anything?

Here's the source code:
https://github.com/chrislondon/Dynamic-Stylesheets/blob/master/mod_dss.c

Feel free to fork my project:
https://github.com/chrislondon/Dynamic-Stylesheets

The README file (
https://github.com/chrislondon/Dynamic-Stylesheets/blob/master/README) contains
usage info and the project contains a simple test case.

Thanks everyone!

Chris London
CTO - Kwista, LLC.
chris@kwista.com

Re: My first Apache module!

Posted by Sorin Manolache <so...@gmail.com>.
On Wed, Aug 24, 2011 at 23:59, Chris London <ch...@kwista.com> wrote:
> Hey everyone,
>
> I don't like to bother mailing lists with beginner questions so I spent
> a few hours on Google looking for info and tutorials. I'm sure at least one
> of you has had that experience :) Anyway, I have finished my first module
> and it works exactly how I want it to.  I still have more features I want to
> add but I'm a little rusty with my C and even worse at Apache Modules. Would
> you mind taking a glance at my code to see if I'm doing anything wrong or
> have any memory leaks or anything?
>
> Here's the source code:
> https://github.com/chrislondon/Dynamic-Stylesheets/blob/master/mod_dss.c
>
> Feel free to fork my project:
> https://github.com/chrislondon/Dynamic-Stylesheets
>
> The README file (
> https://github.com/chrislondon/Dynamic-Stylesheets/blob/master/README) contains
> usage info and the project contains a simple test case.
>
> Thanks everyone!

You open the file but then you exit the handler if r->header_only
without closing the file. Check for r->header_only before opening the
file.

In T_read you allocate cKey, cVal, and temp_node once for every
iteration of the outermost while loop in which *cCurrent == '@' , but
you free this memory only once, outside the while loop.

Also, you do not free correctly your linked list.

S

Re: My first Apache module!

Posted by Nick Kew <ni...@apache.org>.
On 24 Aug 2011, at 22:59, Chris London wrote:

> Hey everyone,
> 
> I don't like to bother mailing lists with beginner questions so I spent
> a few hours on Google looking for info and tutorials.

Good!

> Here's the source code:
> https://github.com/chrislondon/Dynamic-Stylesheets/blob/master/mod_dss.c

Hey, I thought for a moment you were doing something with DSSSL.
You got me all excited!

You're at risk of leaking memory and file descriptors anytime something
sends processing into an error path while they're allocated/open.
The solution is to use pools.  See http://www.apachetutor.org/dev/pools

Less crucially, the APR abstraction of file IO is preferred over FILE*.

Minor point: it's good practice to make your symbols static unless they're
an exported API.  Why is T_fread spilled over to global namespace?

Once you're a bit more confident, you might want to re-write the
parser as a filter, so it can process your data format not just from
a static file but also from a dynamic or proxied source.

-- 
Nick Kew