# What's the meaning ctx-\>srv conf = cscfp-\>ctx-\>srv conf

**URL:** <https://www.ruby-forum.com/t/whats-the-meaning-ctx-srv-conf-cscfp-ctx-srv-conf/200838>\
**Category:** NGINX\
**Created:** [December 23, 2010, 4:09am UTC](https://www.ruby-forum.com/t/whats-the-meaning-ctx-srv-conf-cscfp-ctx-srv-conf/200838 "2010-12-23T04:09:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikuSESS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@nikuSESS](https://www.ruby-forum.com/u/nikuSESS)\
**Post date:** [December 23, 2010, 4:09am UTC](https://www.ruby-forum.com/t/whats-the-meaning-ctx-srv-conf-cscfp-ctx-srv-conf/200838/1 "2010-12-23T04:09:22Z")

</div>

hi~~, now I’m reading the code of nginx-0.9.1.

I readed the code “ctx-\>srv\_conf = cscfp[s]-\>ctx-\>srv\_conf” at line  
593 in the ngx\_http.c .  
but I really don’t understand it’s meaning.

Who can tell me why do this? I find it will make memory leak.

Posted at Nginx Forum:

> **[what's the meaning ? ctx-\>srv\_conf = cscfp\[s\]-\>ctx-\>srv\_conf](https://forum.nginx.org/read.php?2,160626,160626#msg-160626)**
>
> hi~~, now I'm reading the code of nginx-0.9.1. I readed the code "ctx-\>srv\_conf = cscfp\[s\]-\>ctx-\>srv\_conf" at line 593 in the ngx\_http.c . but I really don't understand it's meaning. Who can tell me why do this? I find it will make...

---

<div class="post-metadata">

**Author:** ![garry.lgr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea5d25/32.png) [@garry.lgr](https://www.ruby-forum.com/u/garry.lgr)\
**Post date:** [December 23, 2010, 4:51am UTC](https://www.ruby-forum.com/t/whats-the-meaning-ctx-srv-conf-cscfp-ctx-srv-conf/200838/2 "2010-12-23T04:51:36Z")

</div>

hi, garry:

That code is for changing the context of ‘cf’, and make the ‘cf’  
appropriate for the function ‘merge\_srv\_conf’. I can’t see any thing  
matters  
can cause memory leak unless the “merge\_srv\_conf” function that the  
modules  
provide did this.

---

<div class="post-metadata">

**Author:** ![garry.lgr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea5d25/32.png) [@garry.lgr](https://www.ruby-forum.com/u/garry.lgr)\
**Post date:** [December 23, 2010, 7:47am UTC](https://www.ruby-forum.com/t/whats-the-meaning-ctx-srv-conf-cscfp-ctx-srv-conf/200838/3 "2010-12-23T07:47:34Z")

</div>

![](http://blog.chinaunix.net/photo/6889_101223144343.jpg)  
I drawed a picture according to the code of the nginx-0.9.1. The top  
part in the picture is built in the ngx\_http\_block of ngx\_http.c.

When the ngx\_http\_merge\_servers function at line 277 is called, the  
ctx-\>srv\_conf have hold the address of cf-\>ctx-\>srv\_conf. After  
ctx-\>srv\_conf = cscfp[s]-\>ctx-\>srv\_conf, ctx-\>srv\_conf discard it’s  
older address to point to the new address cscfp[s]-\>ctx-\>srv\_conf.

So I think it will generate memory leak.

Posted at Nginx Forum:

> **[Re: what's the meaning ? ctx-\>srv conf = cscfp\[s\]-\>ctx-\>srv conf](https://forum.nginx.org/read.php?2,160635,160645#msg-160645)**
>
> hi, garry: That code is for changing the context of 'cf', and make the 'cf' appropriate for the function 'merge\_srv\_conf'. I can't see any thing matters can cause memory leak unless the "merge\_srv\_conf" function that the modules provide did...

---

<div class="post-metadata">

**Author:** ![garry.lgr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea5d25/32.png) [@garry.lgr](https://www.ruby-forum.com/u/garry.lgr)\
**Post date:** [December 23, 2010, 8:13am UTC](https://www.ruby-forum.com/t/whats-the-meaning-ctx-srv-conf-cscfp-ctx-srv-conf/200838/4 "2010-12-23T08:13:17Z")

</div>

On Thu, Dec 23, 2010 at 01:46:15AM -0500, garry.lgr wrote:

> ![](http://blog.chinaunix.net/photo/6889_101223144343.jpg)  
> I drawed a picture according to the code of the nginx-0.9.1. The top  
> part in the picture is built in the ngx\_http\_block of ngx\_http.c.
> 
> When the ngx\_http\_merge\_servers function at line 277 is called, the  
> ctx-\>srv\_conf have hold the address of cf-\>ctx-\>srv\_conf. After  
> ctx-\>srv\_conf = cscfp[s]-\>ctx-\>srv\_conf, ctx-\>srv\_conf discard it’s  
> older address to point to the new address cscfp[s]-\>ctx-\>srv\_conf.

Think ctx-\>srv\_conf like a hidden function parameter available via  
cf-\>ctx:

```
 merge_srv_conf(cf, [cf->ctx->srv_conf], ...

```

> So I think it will generate memory leak.

All memory operated in ngx\_http.c and many other files are allocated  
from memory pools freed at once. For example, memory in ngx\_http.c  
is freed after each reconfiguration.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![garry.lgr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea5d25/32.png) [@garry.lgr](https://www.ruby-forum.com/u/garry.lgr)\
**Post date:** [December 23, 2010, 8:52am UTC](https://www.ruby-forum.com/t/whats-the-meaning-ctx-srv-conf-cscfp-ctx-srv-conf/200838/5 "2010-12-23T08:52:06Z")

</div>

Thanks, Igor S…

Now I understood your meaning. As a hidden parameter, that’s very  
smart.

but I looked up the code of many http module files, don’t find any  
where you use this .

Could you tell me where you use it ?

Posted at Nginx Forum:

> **[Re: what's the meaning ? ctx-\>srv conf = cscfp\[s\]-\>ctx-\>srv conf](https://forum.nginx.org/read.php?2,160635,160659#msg-160659)**
>
> hi, garry: That code is for changing the context of 'cf', and make the 'cf' appropriate for the function 'merge\_srv\_conf'. I can't see any thing matters can cause memory leak unless the "merge\_srv\_conf" function that the modules provide did...

---

<div class="post-metadata">

**Author:** ![garry.lgr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea5d25/32.png) [@garry.lgr](https://www.ruby-forum.com/u/garry.lgr)\
**Post date:** [December 23, 2010, 11:11am UTC](https://www.ruby-forum.com/t/whats-the-meaning-ctx-srv-conf-cscfp-ctx-srv-conf/200838/6 "2010-12-23T11:11:29Z")

</div>

ooh, thanks Igor S… now I know it.

Posted at Nginx Forum:

> **[Re: what's the meaning ? ctx-\>srv conf = cscfp\[s\]-\>ctx-\>srv conf](https://forum.nginx.org/read.php?2,160635,160699#msg-160699)**
>
> hi, garry: That code is for changing the context of 'cf', and make the 'cf' appropriate for the function 'merge\_srv\_conf'. I can't see any thing matters can cause memory leak unless the "merge\_srv\_conf" function that the modules provide did...

---

<div class="post-metadata">

**Author:** ![garry.lgr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea5d25/32.png) [@garry.lgr](https://www.ruby-forum.com/u/garry.lgr)\
**Post date:** [December 23, 2010, 9:47am UTC](https://www.ruby-forum.com/t/whats-the-meaning-ctx-srv-conf-cscfp-ctx-srv-conf/200838/7 "2010-12-23T09:47:22Z")

</div>

On Thu, Dec 23, 2010 at 02:51:01AM -0500, garry.lgr wrote:

> Thanks, Igor S..
> 
> Now I understood your meaning. As a hidden parameter, that’s very  
> smart.

I’m not sure that is smart at least in this context.  
It appeared here rather for compatibility reason.

> but I looked up the code of many http module files, don’t find any  
> where you use this .
> 
> Could you tell me where you use it ?

They are used via macros ngx\_http\_conf\_get\_module\_srv\_conf()  
and ngx\_http\_conf\_get\_module\_loc\_conf() in merge phases.  
Currenly only ngx\_http\_conf\_get\_module\_loc\_conf() is used in such  
context  
in proxy, fastcgi, uwscgi and scgi modules.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**
