Skip to contentSkip to conversation

a question about script_setenv in main.c for pppd code

DISCUSSION c4linux 2 participants 2 messages Jul 15, 2008 PPP protocol drivers and compressors

lore
Share & tools
lore

c4linux

author
#0 lore raw

Hi,all:

In main.c:

void
script_setenv(var, value, iskey)

    char *var, *value;
    int iskey;
{
    size_t varl = strlen(var);
    size_t vl = varl + strlen(value) + 2;
    int i;
    char *p, *newstring;

    newstring = (char *) malloc(vl+1);
    if (newstring = 0)
	return;
    *newstring++ = iskey;
    slprintf(newstring, vl, "%s=%s", var, value);

    /* check if this variable is already set */
    if (script_env != 0) {
	for (i = 0; (p = script_env[i]) != 0; ++i) {
	    if (strncmp(p, var, varl) = 0 && p[varl] = '=') {
#ifdef USE_TDB
		if (p[-1] && pppdb != NULL)
		    delete_db_key(p);
#endif
		free(p-1);

......
......

why not free(p) but free(p-1) ?

#1 lore raw
Quoted 9 lines · c4linux writes:
    /* check if this variable is already set */
    if (script_env != 0) {
	for (i = 0; (p = script_env[i]) != 0; ++i) {
	    if (strncmp(p, var, varl) = 0 && p[varl] = '=') {
#ifdef USE_TDB
		if (p[-1] && pppdb != NULL)
		    delete_db_key(p);
#endif
		free(p-1);
Quoted 4 lines

......
......

why not free(p) but free(p-1) ?

It's because of these two lines in that same function:

    *newstring++ = iskey;
[...]
    script_env[i] = newstring;
Signature · 1 line
James Carlson         42.703N 71.076W         <[email protected]>